blob: 8bc58f00c506fae9d24e3452c3a21a4a8c9e8711 [file] [log] [blame]
Duy Truonge833aca2013-02-12 13:35:08 -08001/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
Ankur Nandwanie258cf02011-08-19 10:16:38 -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/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>
Stephen Boyd0ebf7212012-04-30 20:42:35 -070022#include <linux/err.h>
Ankur Nandwanie258cf02011-08-19 10:16:38 -070023#include <mach/irqs.h>
24#include <mach/scm.h>
25#include <mach/subsystem_restart.h>
26#include <mach/subsystem_notif.h>
Sameer Thalappil74743382011-11-10 16:38:58 -080027#include <mach/peripheral-loader.h>
Ankur Nandwanie258cf02011-08-19 10:16:38 -070028#include "smd_private.h"
29#include "ramdump.h"
30
31#define MODULE_NAME "wcnss_8960"
Sunny Kapdic6e42882012-05-30 12:24:48 -070032#define MAX_BUF_SIZE 0x51
Ankur Nandwanie258cf02011-08-19 10:16:38 -070033
Sameer Thalappil74ce6d02012-02-22 07:24:51 -080034static struct delayed_work cancel_vote_work;
Ankur Nandwanie258cf02011-08-19 10:16:38 -070035static void *riva_ramdump_dev;
36static int riva_crash;
37static int ss_restart_inprogress;
Sameer Thalappil74743382011-11-10 16:38:58 -080038static int enable_riva_ssr;
Stephen Boyd0ebf7212012-04-30 20:42:35 -070039static struct subsys_device *riva_8960_dev;
Ankur Nandwanie258cf02011-08-19 10:16:38 -070040
Ankur Nandwanie258cf02011-08-19 10:16:38 -070041static void smsm_state_cb_hdlr(void *data, uint32_t old_state,
42 uint32_t new_state)
43{
Sunny Kapdic6e42882012-05-30 12:24:48 -070044 char *smem_reset_reason;
45 char buffer[MAX_BUF_SIZE];
46 unsigned smem_reset_size;
47 unsigned size;
48
Sameer Thalappil50d62902012-06-15 16:05:51 -070049 riva_crash = true;
50
51 pr_err("%s: smsm state changed\n", MODULE_NAME);
52
Eric Holmberg6866cb72012-03-05 15:29:44 -070053 if (!(new_state & SMSM_RESET))
54 return;
55
Ankur Nandwanie258cf02011-08-19 10:16:38 -070056 if (ss_restart_inprogress) {
57 pr_err("%s: Ignoring smsm reset req, restart in progress\n",
58 MODULE_NAME);
59 return;
60 }
Ankur Nandwanie258cf02011-08-19 10:16:38 -070061
Sameer Thalappild87cf662011-12-12 13:37:31 -080062 if (!enable_riva_ssr)
Sameer Thalappil50d62902012-06-15 16:05:51 -070063 panic(MODULE_NAME ": SMSM reset request received from Riva");
64
65 smem_reset_reason = smem_get_entry(SMEM_SSR_REASON_WCNSS0,
66 &smem_reset_size);
67
68 if (!smem_reset_reason || !smem_reset_size) {
69 pr_err("%s: wcnss subsystem failure reason: %s\n",
70 __func__, "(unknown, smem_get_entry failed)");
71 } else if (!smem_reset_reason[0]) {
72 pr_err("%s: wcnss subsystem failure reason: %s\n",
73 __func__, "(unknown, init string found)");
74 } else {
75 size = smem_reset_size < MAX_BUF_SIZE ? smem_reset_size :
76 (MAX_BUF_SIZE - 1);
77 memcpy(buffer, smem_reset_reason, size);
78 buffer[size] = '\0';
79 pr_err("%s: wcnss subsystem failure reason: %s\n",
80 __func__, buffer);
81 memset(smem_reset_reason, 0, smem_reset_size);
82 wmb();
83 }
84
85 ss_restart_inprogress = true;
Stephen Boyd0ebf7212012-04-30 20:42:35 -070086 subsystem_restart_dev(riva_8960_dev);
Sameer Thalappild87cf662011-12-12 13:37:31 -080087}
88
89static irqreturn_t riva_wdog_bite_irq_hdlr(int irq, void *dev_id)
90{
Sameer Thalappil50d62902012-06-15 16:05:51 -070091 riva_crash = true;
Sameer Thalappild87cf662011-12-12 13:37:31 -080092
93 if (ss_restart_inprogress) {
94 pr_err("%s: Ignoring riva bite irq, restart in progress\n",
95 MODULE_NAME);
96 return IRQ_HANDLED;
97 }
Sameer Thalappil50d62902012-06-15 16:05:51 -070098
99 if (!enable_riva_ssr)
100 panic(MODULE_NAME ": Watchdog bite received from Riva");
101
Sameer Thalappild87cf662011-12-12 13:37:31 -0800102 ss_restart_inprogress = true;
Stephen Boyd0ebf7212012-04-30 20:42:35 -0700103 subsystem_restart_dev(riva_8960_dev);
Sameer Thalappil50d62902012-06-15 16:05:51 -0700104
Sameer Thalappild87cf662011-12-12 13:37:31 -0800105 return IRQ_HANDLED;
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700106}
107
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700108/* SMSM reset Riva */
109static void smsm_riva_reset(void)
110{
111 /* per SS reset request bit is not available now,
112 * all SS host modules are setting this bit
113 * This is still under discussion*/
114 smsm_change_state(SMSM_APPS_STATE, SMSM_RESET, SMSM_RESET);
115}
116
Sameer Thalappil74ce6d02012-02-22 07:24:51 -0800117static void riva_post_bootup(struct work_struct *work)
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700118{
Sameer Thalappil409ed352011-12-07 10:53:31 -0800119 struct platform_device *pdev = wcnss_get_platform_device();
120 struct wcnss_wlan_config *pwlanconfig = wcnss_get_wlan_config();
Sameer Thalappil409ed352011-12-07 10:53:31 -0800121
Sameer Thalappil74ce6d02012-02-22 07:24:51 -0800122 pr_debug(MODULE_NAME ": Cancel APPS vote for Iris & Riva\n");
123
124 wcnss_wlan_power(&pdev->dev, pwlanconfig,
125 WCNSS_WLAN_SWITCH_OFF);
126}
127
128/* Subsystem handlers */
Stephen Boyd0ebf7212012-04-30 20:42:35 -0700129static int riva_shutdown(const struct subsys_desc *subsys)
Sameer Thalappil74ce6d02012-02-22 07:24:51 -0800130{
Sameer Thalappil74743382011-11-10 16:38:58 -0800131 pil_force_shutdown("wcnss");
Sameer Thalappil74ce6d02012-02-22 07:24:51 -0800132 flush_delayed_work(&cancel_vote_work);
Sameer Thalappil13f45182012-07-23 18:02:45 -0700133 wcnss_flush_delayed_boot_votes();
Sameer Thalappil27d3f532012-03-21 15:02:17 -0700134 disable_irq_nosync(RIVA_APSS_WDOG_BITE_RESET_RDY_IRQ);
Sameer Thalappil409ed352011-12-07 10:53:31 -0800135
Sameer Thalappil74ce6d02012-02-22 07:24:51 -0800136 return 0;
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700137}
138
Stephen Boyd0ebf7212012-04-30 20:42:35 -0700139static int riva_powerup(const struct subsys_desc *subsys)
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700140{
Sameer Thalappil409ed352011-12-07 10:53:31 -0800141 struct platform_device *pdev = wcnss_get_platform_device();
142 struct wcnss_wlan_config *pwlanconfig = wcnss_get_wlan_config();
143 int ret = -1;
144
Jeff Johnsondf929982012-11-02 17:35:26 -0700145 wcnss_ssr_boot_notify();
Mekala Natarajanf3d7cba2012-09-27 22:18:55 -0700146
Sameer Thalappil409ed352011-12-07 10:53:31 -0800147 if (pdev && pwlanconfig)
148 ret = wcnss_wlan_power(&pdev->dev, pwlanconfig,
149 WCNSS_WLAN_SWITCH_ON);
Sameer Thalappil6e727d22012-02-14 19:37:54 -0800150 /* delay PIL operation, this SSR may be happening soon after kernel
151 * resumes because of a SMSM RESET by Riva when APPS was suspended.
152 * PIL fails to locate the images without this delay */
153 if (!ret) {
154 msleep(1000);
Sameer Thalappil409ed352011-12-07 10:53:31 -0800155 pil_force_boot("wcnss");
Sameer Thalappil6e727d22012-02-14 19:37:54 -0800156 }
Sameer Thalappild87cf662011-12-12 13:37:31 -0800157 ss_restart_inprogress = false;
158 enable_irq(RIVA_APSS_WDOG_BITE_RESET_RDY_IRQ);
Sameer Thalappil74ce6d02012-02-22 07:24:51 -0800159 schedule_delayed_work(&cancel_vote_work, msecs_to_jiffies(5000));
Sameer Thalappild87cf662011-12-12 13:37:31 -0800160
Sameer Thalappil409ed352011-12-07 10:53:31 -0800161 return ret;
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700162}
163
Jeff Johnson5398d2b2012-10-11 12:09:12 -0700164/* 7MB RAM segments for Riva SS;
165 * Riva 1.1 0x8f000000 - 0x8f700000
166 * Riva 1.0 0x8f200000 - 0x8f700000
167 */
168static struct ramdump_segment riva_segments[] = {{0x8f000000,
169 0x8f700000 - 0x8f000000} };
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700170
Stephen Boyd0ebf7212012-04-30 20:42:35 -0700171static int riva_ramdump(int enable, const struct subsys_desc *subsys)
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700172{
173 pr_debug("%s: enable[%d]\n", MODULE_NAME, enable);
174 if (enable)
175 return do_ramdump(riva_ramdump_dev,
176 riva_segments,
177 ARRAY_SIZE(riva_segments));
178 else
179 return 0;
180}
181
182/* Riva crash handler */
Stephen Boyd0ebf7212012-04-30 20:42:35 -0700183static void riva_crash_shutdown(const struct subsys_desc *subsys)
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700184{
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700185 pr_err("%s: crash shutdown : %d\n", MODULE_NAME, riva_crash);
Sameer Thalappila0c30ae2012-08-13 11:13:06 -0700186 if (riva_crash != true) {
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700187 smsm_riva_reset();
Sameer Thalappila0c30ae2012-08-13 11:13:06 -0700188 /* give sufficient time for wcnss to finish it's error
189 * fatal routine */
Jaeseong GIM393bd8e2012-09-17 17:24:15 +0900190 mdelay(3000);
Sameer Thalappila0c30ae2012-08-13 11:13:06 -0700191 }
192
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700193}
194
Stephen Boyd0ebf7212012-04-30 20:42:35 -0700195static struct subsys_desc riva_8960 = {
Sameer Thalappil3ec03e32012-10-04 17:22:24 -0700196 .name = "wcnss",
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700197 .shutdown = riva_shutdown,
198 .powerup = riva_powerup,
199 .ramdump = riva_ramdump,
200 .crash_shutdown = riva_crash_shutdown
201};
202
Sameer Thalappil74743382011-11-10 16:38:58 -0800203static int enable_riva_ssr_set(const char *val, struct kernel_param *kp)
204{
205 int ret;
206
207 ret = param_set_int(val, kp);
208 if (ret)
209 return ret;
210
211 if (enable_riva_ssr)
212 pr_info(MODULE_NAME ": Subsystem restart activated for riva.\n");
213
214 return 0;
215}
216
217module_param_call(enable_riva_ssr, enable_riva_ssr_set, param_get_int,
218 &enable_riva_ssr, S_IRUGO | S_IWUSR);
219
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700220static int __init riva_restart_init(void)
221{
Stephen Boyd0ebf7212012-04-30 20:42:35 -0700222 riva_8960_dev = subsys_register(&riva_8960);
223 if (IS_ERR(riva_8960_dev))
224 return PTR_ERR(riva_8960_dev);
225 return 0;
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700226}
227
228static int __init riva_ssr_module_init(void)
229{
230 int ret;
231
232 ret = smsm_state_cb_register(SMSM_WCNSS_STATE, SMSM_RESET,
233 smsm_state_cb_hdlr, 0);
234 if (ret < 0) {
Sameer Thalappil50d62902012-06-15 16:05:51 -0700235 pr_err("%s: Unable to register smsm callback for Riva Reset! %d\n",
236 MODULE_NAME, ret);
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700237 goto out;
238 }
Sameer Thalappild87cf662011-12-12 13:37:31 -0800239 ret = request_irq(RIVA_APSS_WDOG_BITE_RESET_RDY_IRQ,
240 riva_wdog_bite_irq_hdlr, IRQF_TRIGGER_HIGH,
241 "riva_wdog", NULL);
242
243 if (ret < 0) {
Sameer Thalappil50d62902012-06-15 16:05:51 -0700244 pr_err("%s: Unable to register for Riva bite interrupt (%d)\n",
245 MODULE_NAME, ret);
Sameer Thalappild87cf662011-12-12 13:37:31 -0800246 goto out;
247 }
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700248 ret = riva_restart_init();
249 if (ret < 0) {
250 pr_err("%s: Unable to register with ssr. (%d)\n",
251 MODULE_NAME, ret);
252 goto out;
253 }
254 riva_ramdump_dev = create_ramdump_device("riva");
255 if (!riva_ramdump_dev) {
256 pr_err("%s: Unable to create ramdump device.\n",
257 MODULE_NAME);
258 ret = -ENOMEM;
259 goto out;
260 }
Sameer Thalappil74ce6d02012-02-22 07:24:51 -0800261 INIT_DELAYED_WORK(&cancel_vote_work, riva_post_bootup);
262
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700263 pr_info("%s: module initialized\n", MODULE_NAME);
264out:
265 return ret;
266}
267
268static void __exit riva_ssr_module_exit(void)
269{
Stephen Boyd0ebf7212012-04-30 20:42:35 -0700270 subsys_unregister(riva_8960_dev);
Ankur Nandwanie258cf02011-08-19 10:16:38 -0700271 free_irq(RIVA_APSS_WDOG_BITE_RESET_RDY_IRQ, NULL);
272}
273
274module_init(riva_ssr_module_init);
275module_exit(riva_ssr_module_exit);
276
277MODULE_LICENSE("GPL v2");