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/regmap.h>
20 #include <asm/system_misc.h>
23 struct regmap *regmap;
24 /* syscfg used for reset */
25 unsigned int offset_rst;
26 unsigned int mask_rst;
27 /* syscfg used for unmask the reset */
28 unsigned int offset_rst_msk;
29 unsigned int mask_rst_msk;
33 #define STIH415_SYSCFG_11 0x2c
34 #define STIH415_SYSCFG_15 0x3c
36 static struct reset_syscfg stih415_reset = {
37 .offset_rst = STIH415_SYSCFG_11,
39 .offset_rst_msk = STIH415_SYSCFG_15,
40 .mask_rst_msk = BIT(0)
44 #define STIH416_SYSCFG_500 0x7d0
45 #define STIH416_SYSCFG_504 0x7e0
47 static struct reset_syscfg stih416_reset = {
48 .offset_rst = STIH416_SYSCFG_500,
50 .offset_rst_msk = STIH416_SYSCFG_504,
51 .mask_rst_msk = BIT(0)
55 #define STIH407_SYSCFG_4000 0x0
56 #define STIH407_SYSCFG_4008 0x20
58 static struct reset_syscfg stih407_reset = {
59 .offset_rst = STIH407_SYSCFG_4000,
61 .offset_rst_msk = STIH407_SYSCFG_4008,
62 .mask_rst_msk = BIT(0)
66 #define STID127_SYSCFG_700 0x0
67 #define STID127_SYSCFG_773 0x124
69 static struct reset_syscfg stid127_reset = {
70 .offset_rst = STID127_SYSCFG_773,
72 .offset_rst_msk = STID127_SYSCFG_700,
73 .mask_rst_msk = BIT(8)
76 static struct reset_syscfg *st_restart_syscfg;
78 static void st_restart(enum reboot_mode reboot_mode, const char *cmd)
80 /* reset syscfg updated */
81 regmap_update_bits(st_restart_syscfg->regmap,
82 st_restart_syscfg->offset_rst,
83 st_restart_syscfg->mask_rst,
86 /* unmask the reset */
87 regmap_update_bits(st_restart_syscfg->regmap,
88 st_restart_syscfg->offset_rst_msk,
89 st_restart_syscfg->mask_rst_msk,
93 static struct of_device_id st_reset_of_match[] = {
95 .compatible = "st,stih415-restart",
96 .data = (void *)&stih415_reset,
98 .compatible = "st,stih416-restart",
99 .data = (void *)&stih416_reset,
101 .compatible = "st,stih407-restart",
102 .data = (void *)&stih407_reset,
104 .compatible = "st,stid127-restart",
105 .data = (void *)&stid127_reset,
110 static int st_reset_probe(struct platform_device *pdev)
112 struct device_node *np = pdev->dev.of_node;
113 const struct of_device_id *match;
114 struct device *dev = &pdev->dev;
116 match = of_match_device(st_reset_of_match, dev);
120 st_restart_syscfg = (struct reset_syscfg *)match->data;
122 st_restart_syscfg->regmap =
123 syscon_regmap_lookup_by_phandle(np, "st,syscfg");
124 if (IS_ERR(st_restart_syscfg->regmap)) {
125 dev_err(dev, "No syscfg phandle specified\n");
126 return PTR_ERR(st_restart_syscfg->regmap);
129 arm_pm_restart = st_restart;
134 static struct platform_driver st_reset_driver = {
135 .probe = st_reset_probe,
138 .of_match_table = st_reset_of_match,
142 static int __init st_reset_init(void)
144 return platform_driver_register(&st_reset_driver);
147 device_initcall(st_reset_init);
149 MODULE_AUTHOR("Christophe Kerello <christophe.kerello@st.com>");
150 MODULE_DESCRIPTION("STMicroelectronics Power off Restart driver");
151 MODULE_LICENSE("GPL v2");