blob: 9a193107c75e658eb0dcd5951cb364f90bdf0b6e [file] [log] [blame]
Bharath Ramachandramurthyff061c72011-06-27 14:22:33 -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/delay.h>
19#include <linux/module.h>
20
21#include <mach/irqs.h>
22#include <mach/scm.h>
23#include <mach/peripheral-loader.h>
24#include <mach/subsystem_restart.h>
25#include <mach/subsystem_notif.h>
26
27#include "smd_private.h"
28#include "ramdump.h"
29
30#define SCM_Q6_NMI_CMD 0x1
31#define MODULE_NAME "lpass_8960"
32#define Q6SS_SOFT_INTR_WAKEUP 0x28800024
33
34/* Subsystem restart: QDSP6 data, functions */
35static void lpass_fatal_fn(struct work_struct *);
36static DECLARE_WORK(lpass_fatal_work, lpass_fatal_fn);
Swaminathan Sathappan71074552011-09-20 10:09:31 -070037void __iomem *q6_wakeup_intr;
Bharath Ramachandramurthyff061c72011-06-27 14:22:33 -070038struct lpass_ssr {
39 void *lpass_ramdump_dev;
40} lpass_ssr;
41
42static struct lpass_ssr lpass_ssr_8960;
Swaminathan Sathappanfc137ec2011-08-16 15:18:41 -070043static int q6_crash_shutdown;
Bharath Ramachandramurthyff061c72011-06-27 14:22:33 -070044
45static void lpass_fatal_fn(struct work_struct *work)
46{
Swaminathan Sathappanfc137ec2011-08-16 15:18:41 -070047 pr_err("%s %s: Watchdog bite received from Q6!\n", MODULE_NAME,
48 __func__);
Bharath Ramachandramurthyff061c72011-06-27 14:22:33 -070049 subsystem_restart("lpass");
50}
51
Swaminathan Sathappanfc137ec2011-08-16 15:18:41 -070052static void lpass_smsm_state_cb(void *data, uint32_t old_state,
53 uint32_t new_state)
54{
55 /* Ignore if we're the one that set SMSM_RESET */
56 if (q6_crash_shutdown)
57 return;
58
59 if (new_state & SMSM_RESET) {
60 pr_err("%s: LPASS SMSM state changed to SMSM_RESET,"
61 " new_state = 0x%x, old_state = 0x%x\n", __func__,
62 new_state, old_state);
63 subsystem_restart("lpass");
64 }
65}
66
Bharath Ramachandramurthyff061c72011-06-27 14:22:33 -070067static void send_q6_nmi(void)
68{
69 /* Send NMI to QDSP6 via an SCM call. */
70 uint32_t cmd = 0x1;
Bharath Ramachandramurthyff061c72011-06-27 14:22:33 -070071
72 scm_call(SCM_SVC_UTIL, SCM_Q6_NMI_CMD,
73 &cmd, sizeof(cmd), NULL, 0);
74
75 /* Wakeup the Q6 */
Swaminathan Sathappan71074552011-09-20 10:09:31 -070076 if (q6_wakeup_intr)
77 writel_relaxed(0x01, q6_wakeup_intr);
Bharath Ramachandramurthyff061c72011-06-27 14:22:33 -070078 mb();
79
80 /* Q6 requires worstcase 100ms to dump caches etc.*/
Swaminathan Sathappan71074552011-09-20 10:09:31 -070081 mdelay(100);
Bharath Ramachandramurthyff061c72011-06-27 14:22:33 -070082 pr_debug("%s: Q6 NMI was sent.\n", __func__);
83}
84
85static int lpass_shutdown(const struct subsys_data *subsys)
86{
87 send_q6_nmi();
88 pil_force_shutdown("q6");
89 disable_irq_nosync(LPASS_Q6SS_WDOG_EXPIRED);
90
91 return 0;
92}
93
94static int lpass_powerup(const struct subsys_data *subsys)
95{
96 int ret = pil_force_boot("q6");
97 enable_irq(LPASS_Q6SS_WDOG_EXPIRED);
98 return ret;
99}
100/* RAM segments - address and size for 8960 */
101static struct ramdump_segment q6_segments[] = { {0x8da00000, 0x8f200000 -
102 0x8da00000}, {0x28400000, 0x20000} };
103static int lpass_ramdump(int enable, const struct subsys_data *subsys)
104{
105 pr_debug("%s: enable[%d]\n", __func__, enable);
106 if (enable)
107 return do_ramdump(lpass_ssr_8960.lpass_ramdump_dev,
108 q6_segments,
109 ARRAY_SIZE(q6_segments));
110 else
111 return 0;
112}
113
114static void lpass_crash_shutdown(const struct subsys_data *subsys)
115{
Swaminathan Sathappanfc137ec2011-08-16 15:18:41 -0700116 q6_crash_shutdown = 1;
Bharath Ramachandramurthyff061c72011-06-27 14:22:33 -0700117 send_q6_nmi();
118}
119
120static irqreturn_t lpass_wdog_bite_irq(int irq, void *dev_id)
121{
122 int ret;
123
124 pr_debug("%s: rxed irq[0x%x]", __func__, irq);
125 disable_irq_nosync(LPASS_Q6SS_WDOG_EXPIRED);
126 ret = schedule_work(&lpass_fatal_work);
127
128 return IRQ_HANDLED;
129}
130
131static struct subsys_data lpass_8960 = {
132 .name = "lpass",
133 .shutdown = lpass_shutdown,
134 .powerup = lpass_powerup,
135 .ramdump = lpass_ramdump,
136 .crash_shutdown = lpass_crash_shutdown
137};
138
139static int __init lpass_restart_init(void)
140{
141 return ssr_register_subsystem(&lpass_8960);
142}
143
144static int __init lpass_fatal_init(void)
145{
146 int ret;
147
Swaminathan Sathappanfc137ec2011-08-16 15:18:41 -0700148 ret = smsm_state_cb_register(SMSM_Q6_STATE, SMSM_RESET,
149 lpass_smsm_state_cb, 0);
150
151 if (ret < 0)
152 pr_err("%s: Unable to register SMSM callback! (%d)\n",
153 __func__, ret);
154
Bharath Ramachandramurthyff061c72011-06-27 14:22:33 -0700155 ret = request_irq(LPASS_Q6SS_WDOG_EXPIRED, lpass_wdog_bite_irq,
156 IRQF_TRIGGER_RISING, "q6_wdog", NULL);
157
158 if (ret < 0) {
159 pr_err("%s: Unable to request LPASS_Q6SS_WDOG_EXPIRED irq.",
160 __func__);
161 goto out;
162 }
163 ret = lpass_restart_init();
164 if (ret < 0) {
165 pr_err("%s: Unable to reg with lpass ssr. (%d)\n",
166 __func__, ret);
167 goto out;
168 }
Swaminathan Sathappan71074552011-09-20 10:09:31 -0700169 q6_wakeup_intr = ioremap_nocache(Q6SS_SOFT_INTR_WAKEUP, 8);
170 if (!q6_wakeup_intr)
171 pr_err("%s: Unable to request q6 wakeup interrupt\n", __func__);
172
Bharath Ramachandramurthyff061c72011-06-27 14:22:33 -0700173 lpass_ssr_8960.lpass_ramdump_dev = create_ramdump_device("lpass");
174
175 if (!lpass_ssr_8960.lpass_ramdump_dev) {
176 pr_err("%s: Unable to create ramdump device.\n",
177 __func__);
178 ret = -ENOMEM;
179 goto out;
180 }
181 pr_info("%s: 8960 lpass SSR driver init'ed.\n", __func__);
182out:
183 return ret;
184}
185
186static void __exit lpass_fatal_exit(void)
187{
Swaminathan Sathappan71074552011-09-20 10:09:31 -0700188 iounmap(q6_wakeup_intr);
Bharath Ramachandramurthyff061c72011-06-27 14:22:33 -0700189 free_irq(LPASS_Q6SS_WDOG_EXPIRED, NULL);
190}
191
192module_init(lpass_fatal_init);
193module_exit(lpass_fatal_exit);
194
195MODULE_LICENSE("GPL v2");