2 * Copyright (C) 2014 STMicroelectronics
4 * Power off Restart driver, used in STMicroelectronics devices.
6 * Author: Christophe Kerello <christophe.kerello@st.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2, as
10 * published by the Free Software Foundation.
13 #include <linux/module.h>
15 #include <linux/of_platform.h>
16 #include <linux/platform_device.h>
17 #include <linux/mfd/syscon.h>
18 #include <linux/reboot.h>
19 #include <linux/regmap.h>
22 struct regmap
*regmap
;
23 /* syscfg used for reset */
24 unsigned int offset_rst
;
25 unsigned int mask_rst
;
26 /* syscfg used for unmask the reset */
27 unsigned int offset_rst_msk
;
28 unsigned int mask_rst_msk
;
32 #define STIH407_SYSCFG_4000 0x0
33 #define STIH407_SYSCFG_4008 0x20
35 static struct reset_syscfg stih407_reset
= {
36 .offset_rst
= STIH407_SYSCFG_4000
,
38 .offset_rst_msk
= STIH407_SYSCFG_4008
,
39 .mask_rst_msk
= BIT(0)
43 static struct reset_syscfg
*st_restart_syscfg
;
45 static int st_restart(struct notifier_block
*this, unsigned long mode
,
48 /* reset syscfg updated */
49 regmap_update_bits(st_restart_syscfg
->regmap
,
50 st_restart_syscfg
->offset_rst
,
51 st_restart_syscfg
->mask_rst
,
54 /* unmask the reset */
55 regmap_update_bits(st_restart_syscfg
->regmap
,
56 st_restart_syscfg
->offset_rst_msk
,
57 st_restart_syscfg
->mask_rst_msk
,
63 static struct notifier_block st_restart_nb
= {
64 .notifier_call
= st_restart
,
68 static const struct of_device_id st_reset_of_match
[] = {
70 .compatible
= "st,stih407-restart",
71 .data
= (void *)&stih407_reset
,
76 static int st_reset_probe(struct platform_device
*pdev
)
78 struct device_node
*np
= pdev
->dev
.of_node
;
79 const struct of_device_id
*match
;
80 struct device
*dev
= &pdev
->dev
;
82 match
= of_match_device(st_reset_of_match
, dev
);
86 st_restart_syscfg
= (struct reset_syscfg
*)match
->data
;
88 st_restart_syscfg
->regmap
=
89 syscon_regmap_lookup_by_phandle(np
, "st,syscfg");
90 if (IS_ERR(st_restart_syscfg
->regmap
)) {
91 dev_err(dev
, "No syscfg phandle specified\n");
92 return PTR_ERR(st_restart_syscfg
->regmap
);
95 return register_restart_handler(&st_restart_nb
);
98 static struct platform_driver st_reset_driver
= {
99 .probe
= st_reset_probe
,
102 .of_match_table
= st_reset_of_match
,
106 static int __init
st_reset_init(void)
108 return platform_driver_register(&st_reset_driver
);
111 device_initcall(st_reset_init
);
113 MODULE_AUTHOR("Christophe Kerello <christophe.kerello@st.com>");
114 MODULE_DESCRIPTION("STMicroelectronics Power off Restart driver");
115 MODULE_LICENSE("GPL v2");