blob: 9970c90a8ad551ecaa122a2814368a78d1b73377 [file] [log] [blame]
Ankur Nandwanie258cf02011-08-19 10:16:38 -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>
Sameer Thalappil409ed352011-12-07 10:53:31 -080020#include <linux/platform_device.h>
21#include <linux/wcnss_wlan.h>
Ankur Nandwanie258cf02011-08-19 10:16:38 -070022#include <mach/irqs.h>
23#include <mach/scm.h>
24#include <mach/subsystem_restart.h>
25#include <mach/subsystem_notif.h>
Sameer Thalappil74743382011-11-10 16:38:58 -080026#include <mach/peripheral-loader.h>
Ankur Nandwanie258cf02011-08-19 10:16:38 -070027#include "smd_private.h"
28#include "ramdump.h"
29
30#define MODULE_NAME "wcnss_8960"
31
32static void riva_smsm_cb_fn(struct work_struct *);
33static DECLARE_WORK(riva_smsm_cb_work, riva_smsm_cb_fn);
34
35static void riva_fatal_fn(struct work_struct *);
36static DECLARE_WORK(riva_fatal_work, riva_fatal_fn);
37
38static void *riva_ramdump_dev;
39static int riva_crash;
40static int ss_restart_inprogress;
Sameer Thalappil74743382011-11-10 16:38:58 -080041static int enable_riva_ssr;
Ankur Nandwanie258cf02011-08-19 10:16:38 -070042
43static void riva_smsm_cb_fn(struct work_struct *work)
44{
Sameer Thalappil74743382011-11-10 16:38:58 -080045 if (!enable_riva_ssr)
46 panic(MODULE_NAME ": SMSM reset request received from Riva");
47 else
48 subsystem_restart("riva");
Ankur Nandwanie258cf02011-08-19 10:16:38 -070049}
50
51static void smsm_state_cb_hdlr(void *data, uint32_t old_state,
52 uint32_t new_state)
53{
54 riva_crash = true;
55 pr_err("%s: smsm state changed to smsm reset\n", MODULE_NAME);
56
57 if (ss_restart_inprogress) {
58 pr_err("%s: Ignoring smsm reset req, restart in progress\n",
59 MODULE_NAME);
60 return;
61 }
Sameer Thalappild87cf662011-12-12 13:37:31 -080062 if (new_state & SMSM_RESET) {
63 ss_restart_inprogress = true;
Ankur Nandwanie258cf02011-08-19 10:16:38 -070064 schedule_work(&riva_smsm_cb_work);
Sameer Thalappild87cf662011-12-12 13:37:31 -080065 }
Ankur Nandwanie258cf02011-08-19 10:16:38 -070066}
67
68static void riva_fatal_fn(struct work_struct *work)
69{
Sameer Thalappild87cf662011-12-12 13:37:31 -080070 if (!enable_riva_ssr)
Sameer Thalappil1806ae12011-10-20 12:45:41 -070071 panic(MODULE_NAME ": Watchdog bite received from Riva");
Sameer Thalappild87cf662011-12-12 13:37:31 -080072 else
73 subsystem_restart("riva");
74}
75
76static irqreturn_t riva_wdog_bite_irq_hdlr(int irq, void *dev_id)
77{
78 int ret;
79
80 if (ss_restart_inprogress) {
81 pr_err("%s: Ignoring riva bite irq, restart in progress\n",
82 MODULE_NAME);
83 return IRQ_HANDLED;
84 }
85 disable_irq_nosync(RIVA_APSS_WDOG_BITE_RESET_RDY_IRQ);
86 ss_restart_inprogress = true;
87 ret = schedule_work(&riva_fatal_work);
88 return IRQ_HANDLED;
Ankur Nandwanie258cf02011-08-19 10:16:38 -070089}
90
Ankur Nandwanie258cf02011-08-19 10:16:38 -070091/* SMSM reset Riva */
92static void smsm_riva_reset(void)
93{
94 /* per SS reset request bit is not available now,
95 * all SS host modules are setting this bit
96 * This is still under discussion*/
97 smsm_change_state(SMSM_APPS_STATE, SMSM_RESET, SMSM_RESET);
98}
99
100/* Subsystem handlers */
101static int riva_shutdown(const struct subsys_data *subsys)
102{
Sameer Thalappil409ed352011-12-07 10:53:31 -0800103 struct platform_device *pdev = wcnss_get_platform_device();
104 struct wcnss_wlan_config *pwlanconfig = wcnss_get_wlan_config();
105 int ret = -1;
106
Sameer Thalappil74743382011-11-10 16:38:58 -0800107 pil_force_shutdown("wcnss");
Sameer Thalappil409ed352011-12-07 10:53:31 -0800108
109 /* proxy vote on behalf of Riva */
110 if (pdev && pwlanconfig)
111 ret = wcnss_wlan_power(&pdev->dev, pwlanconfig,
112 WCNSS_WLAN_SWITCH_OFF);
113 return ret;
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700114}
115
116static int riva_powerup(const struct subsys_data *subsys)
117{
Sameer Thalappil409ed352011-12-07 10:53:31 -0800118 struct platform_device *pdev = wcnss_get_platform_device();
119 struct wcnss_wlan_config *pwlanconfig = wcnss_get_wlan_config();
120 int ret = -1;
121
122 if (pdev && pwlanconfig)
123 ret = wcnss_wlan_power(&pdev->dev, pwlanconfig,
124 WCNSS_WLAN_SWITCH_ON);
Sameer Thalappil6e727d22012-02-14 19:37:54 -0800125 /* delay PIL operation, this SSR may be happening soon after kernel
126 * resumes because of a SMSM RESET by Riva when APPS was suspended.
127 * PIL fails to locate the images without this delay */
128 if (!ret) {
129 msleep(1000);
Sameer Thalappil409ed352011-12-07 10:53:31 -0800130 pil_force_boot("wcnss");
Sameer Thalappil6e727d22012-02-14 19:37:54 -0800131 }
Sameer Thalappild87cf662011-12-12 13:37:31 -0800132 ss_restart_inprogress = false;
133 enable_irq(RIVA_APSS_WDOG_BITE_RESET_RDY_IRQ);
134
Sameer Thalappil409ed352011-12-07 10:53:31 -0800135 return ret;
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700136}
137
138/* RAM segments for Riva SS;
139 * We don't specify the full 5MB allocated for Riva. Only 3MB is specified */
140static struct ramdump_segment riva_segments[] = {{0x8f200000,
141 0x8f500000 - 0x8f200000} };
142
143static int riva_ramdump(int enable, const struct subsys_data *subsys)
144{
145 pr_debug("%s: enable[%d]\n", MODULE_NAME, enable);
146 if (enable)
147 return do_ramdump(riva_ramdump_dev,
148 riva_segments,
149 ARRAY_SIZE(riva_segments));
150 else
151 return 0;
152}
153
154/* Riva crash handler */
155static void riva_crash_shutdown(const struct subsys_data *subsys)
156{
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700157 pr_err("%s: crash shutdown : %d\n", MODULE_NAME, riva_crash);
158 if (riva_crash != true)
159 smsm_riva_reset();
160}
161
162static struct subsys_data riva_8960 = {
163 .name = "riva",
164 .shutdown = riva_shutdown,
165 .powerup = riva_powerup,
166 .ramdump = riva_ramdump,
167 .crash_shutdown = riva_crash_shutdown
168};
169
Sameer Thalappil74743382011-11-10 16:38:58 -0800170static int enable_riva_ssr_set(const char *val, struct kernel_param *kp)
171{
172 int ret;
173
174 ret = param_set_int(val, kp);
175 if (ret)
176 return ret;
177
178 if (enable_riva_ssr)
179 pr_info(MODULE_NAME ": Subsystem restart activated for riva.\n");
180
181 return 0;
182}
183
184module_param_call(enable_riva_ssr, enable_riva_ssr_set, param_get_int,
185 &enable_riva_ssr, S_IRUGO | S_IWUSR);
186
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700187static int __init riva_restart_init(void)
188{
189 return ssr_register_subsystem(&riva_8960);
190}
191
192static int __init riva_ssr_module_init(void)
193{
194 int ret;
195
196 ret = smsm_state_cb_register(SMSM_WCNSS_STATE, SMSM_RESET,
197 smsm_state_cb_hdlr, 0);
198 if (ret < 0) {
199 pr_err("%s: Unable to register smsm callback for Riva Reset!"
200 " (%d)\n", MODULE_NAME, ret);
201 goto out;
202 }
Sameer Thalappild87cf662011-12-12 13:37:31 -0800203 ret = request_irq(RIVA_APSS_WDOG_BITE_RESET_RDY_IRQ,
204 riva_wdog_bite_irq_hdlr, IRQF_TRIGGER_HIGH,
205 "riva_wdog", NULL);
206
207 if (ret < 0) {
208 pr_err("%s: Unable to register for Riva bite interrupt"
209 " (%d)\n", MODULE_NAME, ret);
210 goto out;
211 }
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700212 ret = riva_restart_init();
213 if (ret < 0) {
214 pr_err("%s: Unable to register with ssr. (%d)\n",
215 MODULE_NAME, ret);
216 goto out;
217 }
218 riva_ramdump_dev = create_ramdump_device("riva");
219 if (!riva_ramdump_dev) {
220 pr_err("%s: Unable to create ramdump device.\n",
221 MODULE_NAME);
222 ret = -ENOMEM;
223 goto out;
224 }
225 pr_info("%s: module initialized\n", MODULE_NAME);
226out:
227 return ret;
228}
229
230static void __exit riva_ssr_module_exit(void)
231{
232 free_irq(RIVA_APSS_WDOG_BITE_RESET_RDY_IRQ, NULL);
233}
234
235module_init(riva_ssr_module_init);
236module_exit(riva_ssr_module_exit);
237
238MODULE_LICENSE("GPL v2");