Merge tag 'mac80211-for-john-2014-11-18' of git://git.kernel.org/pub/scm/linux/kernel...
[cascardo/linux.git] / drivers / power / reset / st-poweroff.c
1 /*
2  * Copyright (C) 2014 STMicroelectronics
3  *
4  * Power off Restart driver, used in STMicroelectronics devices.
5  *
6  * Author: Christophe Kerello <christophe.kerello@st.com>
7  *
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.
11  */
12
13 #include <linux/module.h>
14 #include <linux/of.h>
15 #include <linux/of_platform.h>
16 #include <linux/platform_device.h>
17 #include <linux/mfd/syscon.h>
18 #include <linux/regmap.h>
19
20 #include <asm/system_misc.h>
21
22 struct reset_syscfg {
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;
30 };
31
32 /* STiH415 */
33 #define STIH415_SYSCFG_11       0x2c
34 #define STIH415_SYSCFG_15       0x3c
35
36 static struct reset_syscfg stih415_reset = {
37         .offset_rst = STIH415_SYSCFG_11,
38         .mask_rst = BIT(0),
39         .offset_rst_msk = STIH415_SYSCFG_15,
40         .mask_rst_msk = BIT(0)
41 };
42
43 /* STiH416 */
44 #define STIH416_SYSCFG_500      0x7d0
45 #define STIH416_SYSCFG_504      0x7e0
46
47 static struct reset_syscfg stih416_reset = {
48         .offset_rst = STIH416_SYSCFG_500,
49         .mask_rst = BIT(0),
50         .offset_rst_msk = STIH416_SYSCFG_504,
51         .mask_rst_msk = BIT(0)
52 };
53
54 /* STiH407 */
55 #define STIH407_SYSCFG_4000     0x0
56 #define STIH407_SYSCFG_4008     0x20
57
58 static struct reset_syscfg stih407_reset = {
59         .offset_rst = STIH407_SYSCFG_4000,
60         .mask_rst = BIT(0),
61         .offset_rst_msk = STIH407_SYSCFG_4008,
62         .mask_rst_msk = BIT(0)
63 };
64
65 /* STiD127 */
66 #define STID127_SYSCFG_700      0x0
67 #define STID127_SYSCFG_773      0x124
68
69 static struct reset_syscfg stid127_reset = {
70         .offset_rst = STID127_SYSCFG_773,
71         .mask_rst = BIT(0),
72         .offset_rst_msk = STID127_SYSCFG_700,
73         .mask_rst_msk = BIT(8)
74 };
75
76 static struct reset_syscfg *st_restart_syscfg;
77
78 static void st_restart(enum reboot_mode reboot_mode, const char *cmd)
79 {
80         /* reset syscfg updated */
81         regmap_update_bits(st_restart_syscfg->regmap,
82                            st_restart_syscfg->offset_rst,
83                            st_restart_syscfg->mask_rst,
84                            0);
85
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,
90                            0);
91 }
92
93 static struct of_device_id st_reset_of_match[] = {
94         {
95                 .compatible = "st,stih415-restart",
96                 .data = (void *)&stih415_reset,
97         }, {
98                 .compatible = "st,stih416-restart",
99                 .data = (void *)&stih416_reset,
100         }, {
101                 .compatible = "st,stih407-restart",
102                 .data = (void *)&stih407_reset,
103         }, {
104                 .compatible = "st,stid127-restart",
105                 .data = (void *)&stid127_reset,
106         },
107         {}
108 };
109
110 static int st_reset_probe(struct platform_device *pdev)
111 {
112         struct device_node *np = pdev->dev.of_node;
113         const struct of_device_id *match;
114         struct device *dev = &pdev->dev;
115
116         match = of_match_device(st_reset_of_match, dev);
117         if (!match)
118                 return -ENODEV;
119
120         st_restart_syscfg = (struct reset_syscfg *)match->data;
121
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);
127         }
128
129         arm_pm_restart = st_restart;
130
131         return 0;
132 }
133
134 static struct platform_driver st_reset_driver = {
135         .probe = st_reset_probe,
136         .driver = {
137                 .name = "st_reset",
138                 .of_match_table = st_reset_of_match,
139         },
140 };
141
142 static int __init st_reset_init(void)
143 {
144         return platform_driver_register(&st_reset_driver);
145 }
146
147 device_initcall(st_reset_init);
148
149 MODULE_AUTHOR("Christophe Kerello <christophe.kerello@st.com>");
150 MODULE_DESCRIPTION("STMicroelectronics Power off Restart driver");
151 MODULE_LICENSE("GPL v2");