blob: 7df1c3a98dc050d7d2da5894403310bc862c1bca [file] [log] [blame]
Vikram Mulukutla21246482012-03-20 16:30:59 -07001/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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
Saravana Kannan4296f372011-09-21 15:16:22 -070097 /*
98 * Disable the modem watchdog since it keeps running even after the
99 * modem is shutdown.
100 */
101 q6_fw_wdog_addr = ioremap_nocache(Q6_FW_WDOG_ENABLE, 4);
102 if (!q6_fw_wdog_addr)
103 return -ENOMEM;
104
105 q6_sw_wdog_addr = ioremap_nocache(Q6_SW_WDOG_ENABLE, 4);
106 if (!q6_sw_wdog_addr) {
107 iounmap(q6_fw_wdog_addr);
108 return -ENOMEM;
109 }
110
111 writel_relaxed(0x0, q6_fw_wdog_addr);
112 writel_relaxed(0x0, q6_sw_wdog_addr);
113 mb();
114 iounmap(q6_sw_wdog_addr);
115 iounmap(q6_fw_wdog_addr);
116
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -0700117 pil_force_shutdown("modem");
Saravana Kannan0dcf4742011-09-21 17:19:17 -0700118 pil_force_shutdown("modem_fw");
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -0700119 disable_irq_nosync(Q6FW_WDOG_EXPIRED_IRQ);
120 disable_irq_nosync(Q6SW_WDOG_EXPIRED_IRQ);
121
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700122 return 0;
123}
124
125static int modem_powerup(const struct subsys_data *subsys)
126{
Saravana Kannan0dcf4742011-09-21 17:19:17 -0700127 pil_force_boot("modem_fw");
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -0700128 pil_force_boot("modem");
129 enable_irq(Q6FW_WDOG_EXPIRED_IRQ);
130 enable_irq(Q6SW_WDOG_EXPIRED_IRQ);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700131 return 0;
132}
133
134void modem_crash_shutdown(const struct subsys_data *subsys)
135{
136 crash_shutdown = 1;
137 smsm_reset_modem(SMSM_RESET);
138}
139
Vikram Mulukutla09802372011-12-01 10:38:50 -0800140/* FIXME: Get address, size from PIL */
141static struct ramdump_segment modemsw_segments[] = {
142 {0x89000000, 0x8D400000 - 0x89000000},
143};
144
145static struct ramdump_segment modemfw_segments[] = {
146 {0x8D400000, 0x8DA00000 - 0x8D400000},
147};
148
149static struct ramdump_segment smem_segments[] = {
150 {0x80000000, 0x00200000},
151};
152
153static void *modemfw_ramdump_dev;
154static void *modemsw_ramdump_dev;
155static void *smem_ramdump_dev;
156
157static int modem_ramdump(int enable,
158 const struct subsys_data *crashed_subsys)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700159{
Vikram Mulukutla09802372011-12-01 10:38:50 -0800160 int ret = 0;
161
162 if (enable) {
163 ret = do_ramdump(modemsw_ramdump_dev, modemsw_segments,
164 ARRAY_SIZE(modemsw_segments));
165
166 if (ret < 0) {
167 pr_err("Unable to dump modem sw memory (rc = %d).\n",
168 ret);
169 goto out;
170 }
171
172 ret = do_ramdump(modemfw_ramdump_dev, modemfw_segments,
173 ARRAY_SIZE(modemfw_segments));
174
175 if (ret < 0) {
176 pr_err("Unable to dump modem fw memory (rc = %d).\n",
177 ret);
178 goto out;
179 }
180
181 ret = do_ramdump(smem_ramdump_dev, smem_segments,
182 ARRAY_SIZE(smem_segments));
183
184 if (ret < 0) {
185 pr_err("Unable to dump smem memory (rc = %d).\n", ret);
186 goto out;
187 }
188 }
189
190out:
191 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700192}
193
194static irqreturn_t modem_wdog_bite_irq(int irq, void *dev_id)
195{
196 int ret;
197
198 switch (irq) {
199
200 case Q6SW_WDOG_EXPIRED_IRQ:
201 ret = schedule_work(&modem_sw_fatal_work);
202 disable_irq_nosync(Q6SW_WDOG_EXPIRED_IRQ);
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -0700203 disable_irq_nosync(Q6FW_WDOG_EXPIRED_IRQ);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700204 break;
205 case Q6FW_WDOG_EXPIRED_IRQ:
206 ret = schedule_work(&modem_fw_fatal_work);
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -0700207 disable_irq_nosync(Q6SW_WDOG_EXPIRED_IRQ);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700208 disable_irq_nosync(Q6FW_WDOG_EXPIRED_IRQ);
209 break;
210 break;
211
212 default:
213 pr_err("%s: Unknown IRQ!\n", __func__);
214 }
215
216 return IRQ_HANDLED;
217}
218
219static struct subsys_data modem_8960 = {
220 .name = "modem",
221 .shutdown = modem_shutdown,
222 .powerup = modem_powerup,
223 .ramdump = modem_ramdump,
224 .crash_shutdown = modem_crash_shutdown
225};
226
227static int modem_subsystem_restart_init(void)
228{
229 return ssr_register_subsystem(&modem_8960);
230}
231
232static int modem_debug_set(void *data, u64 val)
233{
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -0700234 if (val == 1)
235 subsystem_restart("modem");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700236
237 return 0;
238}
239
240static int modem_debug_get(void *data, u64 *val)
241{
242 *val = 0;
243 return 0;
244}
245
246DEFINE_SIMPLE_ATTRIBUTE(modem_debug_fops, modem_debug_get, modem_debug_set,
247 "%llu\n");
248
249static int modem_debugfs_init(void)
250{
251 struct dentry *dent;
252 dent = debugfs_create_dir("modem_debug", 0);
253
254 if (IS_ERR(dent))
255 return PTR_ERR(dent);
256
257 debugfs_create_file("reset_modem", 0644, dent, NULL,
258 &modem_debug_fops);
259 return 0;
260}
261
262static int __init modem_8960_init(void)
263{
264 int ret;
265
Rohit Vaswani56dd22a2011-11-11 16:21:28 -0800266 if (!cpu_is_msm8960() && !cpu_is_msm8930() && !cpu_is_msm9615())
Stepan Moskovchenko6f594732011-09-20 16:51:47 -0700267 return -ENODEV;
268
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700269 ret = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_RESET,
270 smsm_state_cb, 0);
271
272 if (ret < 0)
273 pr_err("%s: Unable to register SMSM callback! (%d)\n",
274 __func__, ret);
275
276 ret = request_irq(Q6FW_WDOG_EXPIRED_IRQ, modem_wdog_bite_irq,
277 IRQF_TRIGGER_RISING, "modem_wdog_fw", NULL);
278
279 if (ret < 0) {
280 pr_err("%s: Unable to request q6fw watchdog IRQ. (%d)\n",
281 __func__, ret);
282 goto out;
283 }
284
285 ret = request_irq(Q6SW_WDOG_EXPIRED_IRQ, modem_wdog_bite_irq,
286 IRQF_TRIGGER_RISING, "modem_wdog_sw", NULL);
287
288 if (ret < 0) {
289 pr_err("%s: Unable to request q6sw watchdog IRQ. (%d)\n",
290 __func__, ret);
291 disable_irq_nosync(Q6FW_WDOG_EXPIRED_IRQ);
292 goto out;
293 }
294
295 ret = modem_subsystem_restart_init();
296
297 if (ret < 0) {
298 pr_err("%s: Unable to reg with subsystem restart. (%d)\n",
299 __func__, ret);
300 goto out;
301 }
302
Vikram Mulukutla09802372011-12-01 10:38:50 -0800303 modemfw_ramdump_dev = create_ramdump_device("modem_fw");
304
305 if (!modemfw_ramdump_dev) {
306 pr_err("%s: Unable to create modem fw ramdump device. (%d)\n",
307 __func__, -ENOMEM);
308 ret = -ENOMEM;
309 goto out;
310 }
311
312 modemsw_ramdump_dev = create_ramdump_device("modem_sw");
313
314 if (!modemsw_ramdump_dev) {
315 pr_err("%s: Unable to create modem sw ramdump device. (%d)\n",
316 __func__, -ENOMEM);
317 ret = -ENOMEM;
318 goto out;
319 }
320
321 smem_ramdump_dev = create_ramdump_device("smem");
322
323 if (!smem_ramdump_dev) {
324 pr_err("%s: Unable to create smem ramdump device. (%d)\n",
325 __func__, -ENOMEM);
326 ret = -ENOMEM;
327 goto out;
328 }
329
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700330 ret = modem_debugfs_init();
331
Rohit Vaswani56dd22a2011-11-11 16:21:28 -0800332 pr_info("%s: modem fatal driver init'ed.\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700333out:
334 return ret;
335}
336
337module_init(modem_8960_init);