blob: db412849ace5577285b9d4076c299272bf09116d [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>
29#include <mach/irqs-8960.h>
Stepan Moskovchenko6f594732011-09-20 16:51:47 -070030#include <mach/socinfo.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070031
32#include "smd_private.h"
33#include "modem_notifier.h"
34#include "ramdump.h"
35
36static int crash_shutdown;
37
38static void modem_sw_fatal_fn(struct work_struct *work)
39{
40 uint32_t panic_smsm_states = SMSM_RESET | SMSM_SYSTEM_DOWNLOAD;
41 uint32_t reset_smsm_states = SMSM_SYSTEM_REBOOT_USR |
42 SMSM_SYSTEM_PWRDWN_USR;
43 uint32_t modem_state;
44
45 pr_err("Watchdog bite received from modem SW!\n");
46
47 modem_state = smsm_get_state(SMSM_MODEM_STATE);
48
49 if (modem_state & panic_smsm_states) {
50
51 pr_err("Modem SMSM state changed to SMSM_RESET.\n"
52 "Probable err_fatal on the modem. "
53 "Calling subsystem restart...\n");
54 subsystem_restart("modem");
55
56 } else if (modem_state & reset_smsm_states) {
57
58 pr_err("%s: User-invoked system reset/powerdown. "
59 "Resetting the SoC now.\n",
60 __func__);
61 kernel_restart(NULL);
62 } else {
63 /* TODO: Bus unlock code/sequence goes _here_ */
64 subsystem_restart("modem");
65 }
66}
67
68static void modem_fw_fatal_fn(struct work_struct *work)
69{
70 pr_err("Watchdog bite received from modem FW!\n");
71 subsystem_restart("modem");
72}
73
74static DECLARE_WORK(modem_sw_fatal_work, modem_sw_fatal_fn);
75static DECLARE_WORK(modem_fw_fatal_work, modem_fw_fatal_fn);
76
77static void smsm_state_cb(void *data, uint32_t old_state, uint32_t new_state)
78{
79 /* Ignore if we're the one that set SMSM_RESET */
80 if (crash_shutdown)
81 return;
82
83 if (new_state & SMSM_RESET) {
84 pr_err("Modem SMSM state changed to SMSM_RESET.\n"
85 "Probable err_fatal on the modem. "
86 "Calling subsystem restart...\n");
87 subsystem_restart("modem");
88 }
89}
90
91static int modem_shutdown(const struct subsys_data *subsys)
92{
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -070093 int smsm_notif_unregistered = 0;
94
95 if (!(smsm_get_state(SMSM_MODEM_STATE) & SMSM_RESET)) {
96 smsm_state_cb_deregister(SMSM_MODEM_STATE, SMSM_RESET,
97 smsm_state_cb, 0);
98 smsm_notif_unregistered = 1;
99 smsm_reset_modem(SMSM_RESET);
100 }
101
102 pil_force_shutdown("modem");
Saravana Kannan0dcf4742011-09-21 17:19:17 -0700103 pil_force_shutdown("modem_fw");
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -0700104 disable_irq_nosync(Q6FW_WDOG_EXPIRED_IRQ);
105 disable_irq_nosync(Q6SW_WDOG_EXPIRED_IRQ);
106
107 if (smsm_notif_unregistered)
108 smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_RESET,
109 smsm_state_cb, 0);
110
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700111 return 0;
112}
113
114static int modem_powerup(const struct subsys_data *subsys)
115{
Saravana Kannan0dcf4742011-09-21 17:19:17 -0700116 pil_force_boot("modem_fw");
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -0700117 pil_force_boot("modem");
118 enable_irq(Q6FW_WDOG_EXPIRED_IRQ);
119 enable_irq(Q6SW_WDOG_EXPIRED_IRQ);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700120 return 0;
121}
122
123void modem_crash_shutdown(const struct subsys_data *subsys)
124{
125 crash_shutdown = 1;
126 smsm_reset_modem(SMSM_RESET);
127}
128
129int modem_ramdump(int enable, const struct subsys_data *subsys)
130{
131 return 0;
132}
133
134static irqreturn_t modem_wdog_bite_irq(int irq, void *dev_id)
135{
136 int ret;
137
138 switch (irq) {
139
140 case Q6SW_WDOG_EXPIRED_IRQ:
141 ret = schedule_work(&modem_sw_fatal_work);
142 disable_irq_nosync(Q6SW_WDOG_EXPIRED_IRQ);
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -0700143 disable_irq_nosync(Q6FW_WDOG_EXPIRED_IRQ);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700144 break;
145 case Q6FW_WDOG_EXPIRED_IRQ:
146 ret = schedule_work(&modem_fw_fatal_work);
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -0700147 disable_irq_nosync(Q6SW_WDOG_EXPIRED_IRQ);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700148 disable_irq_nosync(Q6FW_WDOG_EXPIRED_IRQ);
149 break;
150 break;
151
152 default:
153 pr_err("%s: Unknown IRQ!\n", __func__);
154 }
155
156 return IRQ_HANDLED;
157}
158
159static struct subsys_data modem_8960 = {
160 .name = "modem",
161 .shutdown = modem_shutdown,
162 .powerup = modem_powerup,
163 .ramdump = modem_ramdump,
164 .crash_shutdown = modem_crash_shutdown
165};
166
167static int modem_subsystem_restart_init(void)
168{
169 return ssr_register_subsystem(&modem_8960);
170}
171
172static int modem_debug_set(void *data, u64 val)
173{
Vikram Mulukutla976ff0a2011-08-31 12:06:53 -0700174 if (val == 1)
175 subsystem_restart("modem");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700176
177 return 0;
178}
179
180static int modem_debug_get(void *data, u64 *val)
181{
182 *val = 0;
183 return 0;
184}
185
186DEFINE_SIMPLE_ATTRIBUTE(modem_debug_fops, modem_debug_get, modem_debug_set,
187 "%llu\n");
188
189static int modem_debugfs_init(void)
190{
191 struct dentry *dent;
192 dent = debugfs_create_dir("modem_debug", 0);
193
194 if (IS_ERR(dent))
195 return PTR_ERR(dent);
196
197 debugfs_create_file("reset_modem", 0644, dent, NULL,
198 &modem_debug_fops);
199 return 0;
200}
201
202static int __init modem_8960_init(void)
203{
204 int ret;
205
Stepan Moskovchenko6f594732011-09-20 16:51:47 -0700206 if (!cpu_is_msm8960())
207 return -ENODEV;
208
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700209 ret = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_RESET,
210 smsm_state_cb, 0);
211
212 if (ret < 0)
213 pr_err("%s: Unable to register SMSM callback! (%d)\n",
214 __func__, ret);
215
216 ret = request_irq(Q6FW_WDOG_EXPIRED_IRQ, modem_wdog_bite_irq,
217 IRQF_TRIGGER_RISING, "modem_wdog_fw", NULL);
218
219 if (ret < 0) {
220 pr_err("%s: Unable to request q6fw watchdog IRQ. (%d)\n",
221 __func__, ret);
222 goto out;
223 }
224
225 ret = request_irq(Q6SW_WDOG_EXPIRED_IRQ, modem_wdog_bite_irq,
226 IRQF_TRIGGER_RISING, "modem_wdog_sw", NULL);
227
228 if (ret < 0) {
229 pr_err("%s: Unable to request q6sw watchdog IRQ. (%d)\n",
230 __func__, ret);
231 disable_irq_nosync(Q6FW_WDOG_EXPIRED_IRQ);
232 goto out;
233 }
234
235 ret = modem_subsystem_restart_init();
236
237 if (ret < 0) {
238 pr_err("%s: Unable to reg with subsystem restart. (%d)\n",
239 __func__, ret);
240 goto out;
241 }
242
243 ret = modem_debugfs_init();
244
245 pr_info("%s: 8960 modem fatal driver init'ed.\n", __func__);
246out:
247 return ret;
248}
249
250module_init(modem_8960_init);