blob: 907a1cf60ab2fd689bc94c579e55ceb25f5007da [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>
30
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
90static int modem_shutdown(const struct subsys_data *subsys)
91{
92 /* TODO: Call into PIL to shutdown the modem */
93 return 0;
94}
95
96static int modem_powerup(const struct subsys_data *subsys)
97{
98 /* TODO: Call into PIL to powerup the modem */
99 return 0;
100}
101
102void modem_crash_shutdown(const struct subsys_data *subsys)
103{
104 crash_shutdown = 1;
105 smsm_reset_modem(SMSM_RESET);
106}
107
108int modem_ramdump(int enable, const struct subsys_data *subsys)
109{
110 return 0;
111}
112
113static irqreturn_t modem_wdog_bite_irq(int irq, void *dev_id)
114{
115 int ret;
116
117 switch (irq) {
118
119 case Q6SW_WDOG_EXPIRED_IRQ:
120 ret = schedule_work(&modem_sw_fatal_work);
121 disable_irq_nosync(Q6SW_WDOG_EXPIRED_IRQ);
122 break;
123 case Q6FW_WDOG_EXPIRED_IRQ:
124 ret = schedule_work(&modem_fw_fatal_work);
125 disable_irq_nosync(Q6FW_WDOG_EXPIRED_IRQ);
126 break;
127 break;
128
129 default:
130 pr_err("%s: Unknown IRQ!\n", __func__);
131 }
132
133 return IRQ_HANDLED;
134}
135
136static struct subsys_data modem_8960 = {
137 .name = "modem",
138 .shutdown = modem_shutdown,
139 .powerup = modem_powerup,
140 .ramdump = modem_ramdump,
141 .crash_shutdown = modem_crash_shutdown
142};
143
144static int modem_subsystem_restart_init(void)
145{
146 return ssr_register_subsystem(&modem_8960);
147}
148
149static int modem_debug_set(void *data, u64 val)
150{
151 if (val == 1) {
152 pr_info("%s: Intentionally setting the SMSM_RESET bit.\n",
153 __func__);
154 smsm_reset_modem(SMSM_RESET);
155 }
156
157 return 0;
158}
159
160static int modem_debug_get(void *data, u64 *val)
161{
162 *val = 0;
163 return 0;
164}
165
166DEFINE_SIMPLE_ATTRIBUTE(modem_debug_fops, modem_debug_get, modem_debug_set,
167 "%llu\n");
168
169static int modem_debugfs_init(void)
170{
171 struct dentry *dent;
172 dent = debugfs_create_dir("modem_debug", 0);
173
174 if (IS_ERR(dent))
175 return PTR_ERR(dent);
176
177 debugfs_create_file("reset_modem", 0644, dent, NULL,
178 &modem_debug_fops);
179 return 0;
180}
181
182static int __init modem_8960_init(void)
183{
184 int ret;
185
186 ret = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_RESET,
187 smsm_state_cb, 0);
188
189 if (ret < 0)
190 pr_err("%s: Unable to register SMSM callback! (%d)\n",
191 __func__, ret);
192
193 ret = request_irq(Q6FW_WDOG_EXPIRED_IRQ, modem_wdog_bite_irq,
194 IRQF_TRIGGER_RISING, "modem_wdog_fw", NULL);
195
196 if (ret < 0) {
197 pr_err("%s: Unable to request q6fw watchdog IRQ. (%d)\n",
198 __func__, ret);
199 goto out;
200 }
201
202 ret = request_irq(Q6SW_WDOG_EXPIRED_IRQ, modem_wdog_bite_irq,
203 IRQF_TRIGGER_RISING, "modem_wdog_sw", NULL);
204
205 if (ret < 0) {
206 pr_err("%s: Unable to request q6sw watchdog IRQ. (%d)\n",
207 __func__, ret);
208 disable_irq_nosync(Q6FW_WDOG_EXPIRED_IRQ);
209 goto out;
210 }
211
212 ret = modem_subsystem_restart_init();
213
214 if (ret < 0) {
215 pr_err("%s: Unable to reg with subsystem restart. (%d)\n",
216 __func__, ret);
217 goto out;
218 }
219
220 ret = modem_debugfs_init();
221
222 pr_info("%s: 8960 modem fatal driver init'ed.\n", __func__);
223out:
224 return ret;
225}
226
227module_init(modem_8960_init);