blob: f0aa13c414632e041ca91da31eedd69c996ecb3a [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/kernel.h>
14#include <linux/interrupt.h>
15#include <linux/reboot.h>
16#include <linux/workqueue.h>
17#include <linux/io.h>
18#include <linux/jiffies.h>
19#include <linux/stringify.h>
20#include <linux/delay.h>
21#include <linux/module.h>
22#include <linux/debugfs.h>
23
24#include <mach/irqs.h>
25#include <mach/scm.h>
26#include <mach/peripheral-loader.h>
27#include <mach/subsystem_restart.h>
28#include <mach/subsystem_notif.h>
Stepan Moskovchenko6f594732011-09-20 16:51:47 -070029#include <mach/socinfo.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070030
31#include "smd_private.h"
32#include "modem_notifier.h"
33#include "ramdump.h"
34
35static int crash_shutdown;
36
37static void modem_sw_fatal_fn(struct work_struct *work)
38{
39 uint32_t panic_smsm_states = SMSM_RESET | SMSM_SYSTEM_DOWNLOAD;
40 uint32_t reset_smsm_states = SMSM_SYSTEM_REBOOT_USR |
41 SMSM_SYSTEM_PWRDWN_USR;
42 uint32_t modem_state;
43
44 pr_err("Watchdog bite received from modem SW!\n");
45
46 modem_state = smsm_get_state(SMSM_MODEM_STATE);
47
48 if (modem_state & panic_smsm_states) {
49
50 pr_err("Modem SMSM state changed to SMSM_RESET.\n"
51 "Probable err_fatal on the modem. "
52 "Calling subsystem restart...\n");
53 subsystem_restart("modem");
54
55 } else if (modem_state & reset_smsm_states) {
56
57 pr_err("%s: User-invoked system reset/powerdown. "
58 "Resetting the SoC now.\n",
59 __func__);
60 kernel_restart(NULL);
61 } else {
62 /* TODO: Bus unlock code/sequence goes _here_ */
63 subsystem_restart("modem");
64 }
65}
66
67static void modem_fw_fatal_fn(struct work_struct *work)
68{
69 pr_err("Watchdog bite received from modem FW!\n");
70 subsystem_restart("modem");
71}
72
73static DECLARE_WORK(modem_sw_fatal_work, modem_sw_fatal_fn);
74static DECLARE_WORK(modem_fw_fatal_work, modem_fw_fatal_fn);
75
76static void smsm_state_cb(void *data, uint32_t old_state, uint32_t new_state)
77{
78 /* Ignore if we're the one that set SMSM_RESET */
79 if (crash_shutdown)
80 return;
81
82 if (new_state & SMSM_RESET) {
83 pr_err("Modem SMSM state changed to SMSM_RESET.\n"
84 "Probable err_fatal on the modem. "
85 "Calling subsystem restart...\n");
86 subsystem_restart("modem");
87 }
88}
89
Saravana Kannan4296f372011-09-21 15:16:22 -070090#define Q6_FW_WDOG_ENABLE 0x08882024
91#define Q6_SW_WDOG_ENABLE 0x08982024
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070092static int modem_shutdown(const struct subsys_data *subsys)
93{
Saravana Kannan4296f372011-09-21 15:16:22 -070094 void __iomem *q6_fw_wdog_addr;
95 void __iomem *q6_sw_wdog_addr;
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -070096 int smsm_notif_unregistered = 0;
97
98 if (!(smsm_get_state(SMSM_MODEM_STATE) & SMSM_RESET)) {
99 smsm_state_cb_deregister(SMSM_MODEM_STATE, SMSM_RESET,
100 smsm_state_cb, 0);
101 smsm_notif_unregistered = 1;
102 smsm_reset_modem(SMSM_RESET);
103 }
104
Saravana Kannan4296f372011-09-21 15:16:22 -0700105 /*
106 * Disable the modem watchdog since it keeps running even after the
107 * modem is shutdown.
108 */
109 q6_fw_wdog_addr = ioremap_nocache(Q6_FW_WDOG_ENABLE, 4);
110 if (!q6_fw_wdog_addr)
111 return -ENOMEM;
112
113 q6_sw_wdog_addr = ioremap_nocache(Q6_SW_WDOG_ENABLE, 4);
114 if (!q6_sw_wdog_addr) {
115 iounmap(q6_fw_wdog_addr);
116 return -ENOMEM;
117 }
118
119 writel_relaxed(0x0, q6_fw_wdog_addr);
120 writel_relaxed(0x0, q6_sw_wdog_addr);
121 mb();
122 iounmap(q6_sw_wdog_addr);
123 iounmap(q6_fw_wdog_addr);
124
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -0700125 pil_force_shutdown("modem");
Saravana Kannan0dcf4742011-09-21 17:19:17 -0700126 pil_force_shutdown("modem_fw");
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -0700127 disable_irq_nosync(Q6FW_WDOG_EXPIRED_IRQ);
128 disable_irq_nosync(Q6SW_WDOG_EXPIRED_IRQ);
129
130 if (smsm_notif_unregistered)
131 smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_RESET,
132 smsm_state_cb, 0);
133
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700134 return 0;
135}
136
137static int modem_powerup(const struct subsys_data *subsys)
138{
Saravana Kannan0dcf4742011-09-21 17:19:17 -0700139 pil_force_boot("modem_fw");
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -0700140 pil_force_boot("modem");
141 enable_irq(Q6FW_WDOG_EXPIRED_IRQ);
142 enable_irq(Q6SW_WDOG_EXPIRED_IRQ);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700143 return 0;
144}
145
146void modem_crash_shutdown(const struct subsys_data *subsys)
147{
148 crash_shutdown = 1;
149 smsm_reset_modem(SMSM_RESET);
150}
151
152int modem_ramdump(int enable, const struct subsys_data *subsys)
153{
154 return 0;
155}
156
157static irqreturn_t modem_wdog_bite_irq(int irq, void *dev_id)
158{
159 int ret;
160
161 switch (irq) {
162
163 case Q6SW_WDOG_EXPIRED_IRQ:
164 ret = schedule_work(&modem_sw_fatal_work);
165 disable_irq_nosync(Q6SW_WDOG_EXPIRED_IRQ);
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -0700166 disable_irq_nosync(Q6FW_WDOG_EXPIRED_IRQ);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700167 break;
168 case Q6FW_WDOG_EXPIRED_IRQ:
169 ret = schedule_work(&modem_fw_fatal_work);
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -0700170 disable_irq_nosync(Q6SW_WDOG_EXPIRED_IRQ);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700171 disable_irq_nosync(Q6FW_WDOG_EXPIRED_IRQ);
172 break;
173 break;
174
175 default:
176 pr_err("%s: Unknown IRQ!\n", __func__);
177 }
178
179 return IRQ_HANDLED;
180}
181
182static struct subsys_data modem_8960 = {
183 .name = "modem",
184 .shutdown = modem_shutdown,
185 .powerup = modem_powerup,
186 .ramdump = modem_ramdump,
187 .crash_shutdown = modem_crash_shutdown
188};
189
190static int modem_subsystem_restart_init(void)
191{
192 return ssr_register_subsystem(&modem_8960);
193}
194
195static int modem_debug_set(void *data, u64 val)
196{
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -0700197 if (val == 1)
198 subsystem_restart("modem");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700199
200 return 0;
201}
202
203static int modem_debug_get(void *data, u64 *val)
204{
205 *val = 0;
206 return 0;
207}
208
209DEFINE_SIMPLE_ATTRIBUTE(modem_debug_fops, modem_debug_get, modem_debug_set,
210 "%llu\n");
211
212static int modem_debugfs_init(void)
213{
214 struct dentry *dent;
215 dent = debugfs_create_dir("modem_debug", 0);
216
217 if (IS_ERR(dent))
218 return PTR_ERR(dent);
219
220 debugfs_create_file("reset_modem", 0644, dent, NULL,
221 &modem_debug_fops);
222 return 0;
223}
224
225static int __init modem_8960_init(void)
226{
227 int ret;
228
Rohit Vaswani56dd22a2011-11-11 16:21:28 -0800229 if (!cpu_is_msm8960() && !cpu_is_msm8930() && !cpu_is_msm9615())
Stepan Moskovchenko6f594732011-09-20 16:51:47 -0700230 return -ENODEV;
231
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700232 ret = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_RESET,
233 smsm_state_cb, 0);
234
235 if (ret < 0)
236 pr_err("%s: Unable to register SMSM callback! (%d)\n",
237 __func__, ret);
238
239 ret = request_irq(Q6FW_WDOG_EXPIRED_IRQ, modem_wdog_bite_irq,
240 IRQF_TRIGGER_RISING, "modem_wdog_fw", NULL);
241
242 if (ret < 0) {
243 pr_err("%s: Unable to request q6fw watchdog IRQ. (%d)\n",
244 __func__, ret);
245 goto out;
246 }
247
248 ret = request_irq(Q6SW_WDOG_EXPIRED_IRQ, modem_wdog_bite_irq,
249 IRQF_TRIGGER_RISING, "modem_wdog_sw", NULL);
250
251 if (ret < 0) {
252 pr_err("%s: Unable to request q6sw watchdog IRQ. (%d)\n",
253 __func__, ret);
254 disable_irq_nosync(Q6FW_WDOG_EXPIRED_IRQ);
255 goto out;
256 }
257
258 ret = modem_subsystem_restart_init();
259
260 if (ret < 0) {
261 pr_err("%s: Unable to reg with subsystem restart. (%d)\n",
262 __func__, ret);
263 goto out;
264 }
265
266 ret = modem_debugfs_init();
267
Rohit Vaswani56dd22a2011-11-11 16:21:28 -0800268 pr_info("%s: modem fatal driver init'ed.\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700269out:
270 return ret;
271}
272
273module_init(modem_8960_init);