Duy Truong | e833aca | 2013-02-12 13:35:08 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 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> |
Sriranjan Srikantam | 6b2899c | 2011-10-10 16:28:49 -0700 | [diff] [blame] | 20 | #include <linux/err.h> |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 21 | |
| 22 | #include <mach/irqs.h> |
| 23 | #include <mach/scm.h> |
| 24 | #include <mach/peripheral-loader.h> |
| 25 | #include <mach/subsystem_restart.h> |
| 26 | #include <mach/subsystem_notif.h> |
| 27 | |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 28 | #if defined(CONFIG_LGE_CRASH_HANDLER) |
| 29 | #include <mach/restart.h> |
| 30 | #include <mach/board_lge.h> |
| 31 | #endif |
| 32 | |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 33 | #include "smd_private.h" |
| 34 | #include "ramdump.h" |
Sriranjan Srikantam | 6b2899c | 2011-10-10 16:28:49 -0700 | [diff] [blame] | 35 | #include "sysmon.h" |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 36 | |
| 37 | #define SCM_Q6_NMI_CMD 0x1 |
| 38 | #define MODULE_NAME "lpass_8960" |
Ravishankar Sarawadi | de25116 | 2012-03-23 12:47:03 -0700 | [diff] [blame] | 39 | #define MAX_BUF_SIZE 0x51 |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 40 | |
| 41 | /* Subsystem restart: QDSP6 data, functions */ |
| 42 | static void lpass_fatal_fn(struct work_struct *); |
| 43 | static DECLARE_WORK(lpass_fatal_work, lpass_fatal_fn); |
| 44 | struct lpass_ssr { |
| 45 | void *lpass_ramdump_dev; |
| 46 | } lpass_ssr; |
| 47 | |
| 48 | static struct lpass_ssr lpass_ssr_8960; |
Swaminathan Sathappan | fc137ec | 2011-08-16 15:18:41 -0700 | [diff] [blame] | 49 | static int q6_crash_shutdown; |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 50 | |
Sriranjan Srikantam | 6b2899c | 2011-10-10 16:28:49 -0700 | [diff] [blame] | 51 | static int riva_notifier_cb(struct notifier_block *this, unsigned long code, |
| 52 | void *ss_handle) |
| 53 | { |
| 54 | int ret; |
| 55 | switch (code) { |
| 56 | case SUBSYS_BEFORE_SHUTDOWN: |
| 57 | pr_debug("%s: R-Notify: Shutdown started\n", __func__); |
| 58 | ret = sysmon_send_event(SYSMON_SS_LPASS, "wcnss", |
| 59 | SUBSYS_BEFORE_SHUTDOWN); |
| 60 | if (ret < 0) |
| 61 | pr_err("%s: sysmon_send_event error %d", __func__, |
| 62 | ret); |
| 63 | break; |
| 64 | } |
| 65 | return NOTIFY_DONE; |
| 66 | } |
| 67 | |
| 68 | static void *ssr_notif_hdle; |
| 69 | static struct notifier_block rnb = { |
| 70 | .notifier_call = riva_notifier_cb, |
| 71 | }; |
| 72 | |
Sriranjan Srikantam | 3d907a6 | 2011-10-11 12:51:25 -0700 | [diff] [blame] | 73 | static int modem_notifier_cb(struct notifier_block *this, unsigned long code, |
| 74 | void *ss_handle) |
| 75 | { |
| 76 | int ret; |
| 77 | switch (code) { |
| 78 | case SUBSYS_BEFORE_SHUTDOWN: |
| 79 | pr_debug("%s: M-Notify: Shutdown started\n", __func__); |
| 80 | ret = sysmon_send_event(SYSMON_SS_LPASS, "modem", |
| 81 | SUBSYS_BEFORE_SHUTDOWN); |
| 82 | if (ret < 0) |
| 83 | pr_err("%s: sysmon_send_event error %d", __func__, |
| 84 | ret); |
| 85 | break; |
| 86 | } |
| 87 | return NOTIFY_DONE; |
| 88 | } |
| 89 | |
| 90 | static void *ssr_modem_notif_hdle; |
| 91 | static struct notifier_block mnb = { |
| 92 | .notifier_call = modem_notifier_cb, |
| 93 | }; |
| 94 | |
Ravishankar Sarawadi | de25116 | 2012-03-23 12:47:03 -0700 | [diff] [blame] | 95 | static void lpass_log_failure_reason(void) |
| 96 | { |
| 97 | char *reason; |
| 98 | char buffer[MAX_BUF_SIZE]; |
| 99 | unsigned size; |
| 100 | |
| 101 | reason = smem_get_entry(SMEM_SSR_REASON_LPASS0, &size); |
| 102 | |
| 103 | if (!reason) { |
| 104 | pr_err("%s: subsystem failure reason: (unknown, smem_get_entry failed).", |
| 105 | MODULE_NAME); |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | if (reason[0] == '\0') { |
| 110 | pr_err("%s: subsystem failure reason: (unknown, init value found)", |
| 111 | MODULE_NAME); |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | size = size < MAX_BUF_SIZE ? size : (MAX_BUF_SIZE-1); |
| 116 | memcpy(buffer, reason, size); |
| 117 | buffer[size] = '\0'; |
| 118 | pr_err("%s: subsystem failure reason: %s", MODULE_NAME, buffer); |
| 119 | memset((void *)reason, 0x0, size); |
| 120 | wmb(); |
| 121 | } |
| 122 | |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 123 | static void lpass_fatal_fn(struct work_struct *work) |
| 124 | { |
Swaminathan Sathappan | fc137ec | 2011-08-16 15:18:41 -0700 | [diff] [blame] | 125 | pr_err("%s %s: Watchdog bite received from Q6!\n", MODULE_NAME, |
| 126 | __func__); |
Ravishankar Sarawadi | de25116 | 2012-03-23 12:47:03 -0700 | [diff] [blame] | 127 | lpass_log_failure_reason(); |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 128 | #if defined(CONFIG_LGE_CRASH_HANDLER) |
| 129 | set_ssr_magic_number("lpass"); |
| 130 | msm_set_restart_mode(0x6d634130); |
| 131 | #endif |
Swaminathan Sathappan | 00f766d | 2011-09-29 15:35:55 -0700 | [diff] [blame] | 132 | panic(MODULE_NAME ": Resetting the SoC"); |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Swaminathan Sathappan | fc137ec | 2011-08-16 15:18:41 -0700 | [diff] [blame] | 135 | static void lpass_smsm_state_cb(void *data, uint32_t old_state, |
| 136 | uint32_t new_state) |
| 137 | { |
| 138 | /* Ignore if we're the one that set SMSM_RESET */ |
| 139 | if (q6_crash_shutdown) |
| 140 | return; |
| 141 | |
| 142 | if (new_state & SMSM_RESET) { |
| 143 | pr_err("%s: LPASS SMSM state changed to SMSM_RESET," |
| 144 | " new_state = 0x%x, old_state = 0x%x\n", __func__, |
| 145 | new_state, old_state); |
Ravishankar Sarawadi | de25116 | 2012-03-23 12:47:03 -0700 | [diff] [blame] | 146 | lpass_log_failure_reason(); |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 147 | #if defined(CONFIG_LGE_CRASH_HANDLER) |
| 148 | set_ssr_magic_number("lpass"); |
| 149 | msm_set_restart_mode(0x6d634130); |
| 150 | #endif |
Swaminathan Sathappan | 00f766d | 2011-09-29 15:35:55 -0700 | [diff] [blame] | 151 | panic(MODULE_NAME ": Resetting the SoC"); |
Swaminathan Sathappan | fc137ec | 2011-08-16 15:18:41 -0700 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 155 | static void send_q6_nmi(void) |
| 156 | { |
| 157 | /* Send NMI to QDSP6 via an SCM call. */ |
| 158 | uint32_t cmd = 0x1; |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 159 | |
| 160 | scm_call(SCM_SVC_UTIL, SCM_Q6_NMI_CMD, |
| 161 | &cmd, sizeof(cmd), NULL, 0); |
| 162 | |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 163 | /* Q6 requires worstcase 100ms to dump caches etc.*/ |
Swaminathan Sathappan | 7107455 | 2011-09-20 10:09:31 -0700 | [diff] [blame] | 164 | mdelay(100); |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 165 | pr_debug("%s: Q6 NMI was sent.\n", __func__); |
| 166 | } |
| 167 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 168 | static int lpass_shutdown(const struct subsys_desc *subsys) |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 169 | { |
| 170 | send_q6_nmi(); |
| 171 | pil_force_shutdown("q6"); |
| 172 | disable_irq_nosync(LPASS_Q6SS_WDOG_EXPIRED); |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 177 | static int lpass_powerup(const struct subsys_desc *subsys) |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 178 | { |
| 179 | int ret = pil_force_boot("q6"); |
| 180 | enable_irq(LPASS_Q6SS_WDOG_EXPIRED); |
| 181 | return ret; |
| 182 | } |
| 183 | /* RAM segments - address and size for 8960 */ |
| 184 | static struct ramdump_segment q6_segments[] = { {0x8da00000, 0x8f200000 - |
| 185 | 0x8da00000}, {0x28400000, 0x20000} }; |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 186 | static int lpass_ramdump(int enable, const struct subsys_desc *subsys) |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 187 | { |
| 188 | pr_debug("%s: enable[%d]\n", __func__, enable); |
| 189 | if (enable) |
| 190 | return do_ramdump(lpass_ssr_8960.lpass_ramdump_dev, |
| 191 | q6_segments, |
| 192 | ARRAY_SIZE(q6_segments)); |
| 193 | else |
| 194 | return 0; |
| 195 | } |
| 196 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 197 | static void lpass_crash_shutdown(const struct subsys_desc *subsys) |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 198 | { |
Swaminathan Sathappan | fc137ec | 2011-08-16 15:18:41 -0700 | [diff] [blame] | 199 | q6_crash_shutdown = 1; |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 200 | send_q6_nmi(); |
| 201 | } |
| 202 | |
| 203 | static irqreturn_t lpass_wdog_bite_irq(int irq, void *dev_id) |
| 204 | { |
| 205 | int ret; |
| 206 | |
| 207 | pr_debug("%s: rxed irq[0x%x]", __func__, irq); |
| 208 | disable_irq_nosync(LPASS_Q6SS_WDOG_EXPIRED); |
| 209 | ret = schedule_work(&lpass_fatal_work); |
| 210 | |
| 211 | return IRQ_HANDLED; |
| 212 | } |
| 213 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 214 | static struct subsys_device *lpass_8960_dev; |
| 215 | |
| 216 | static struct subsys_desc lpass_8960 = { |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 217 | .name = "lpass", |
| 218 | .shutdown = lpass_shutdown, |
| 219 | .powerup = lpass_powerup, |
| 220 | .ramdump = lpass_ramdump, |
| 221 | .crash_shutdown = lpass_crash_shutdown |
| 222 | }; |
| 223 | |
| 224 | static int __init lpass_restart_init(void) |
| 225 | { |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 226 | lpass_8960_dev = subsys_register(&lpass_8960); |
| 227 | if (IS_ERR(lpass_8960_dev)) |
| 228 | return PTR_ERR(lpass_8960_dev); |
| 229 | return 0; |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | static int __init lpass_fatal_init(void) |
| 233 | { |
| 234 | int ret; |
| 235 | |
Swaminathan Sathappan | fc137ec | 2011-08-16 15:18:41 -0700 | [diff] [blame] | 236 | ret = smsm_state_cb_register(SMSM_Q6_STATE, SMSM_RESET, |
| 237 | lpass_smsm_state_cb, 0); |
| 238 | |
| 239 | if (ret < 0) |
| 240 | pr_err("%s: Unable to register SMSM callback! (%d)\n", |
| 241 | __func__, ret); |
| 242 | |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 243 | ret = request_irq(LPASS_Q6SS_WDOG_EXPIRED, lpass_wdog_bite_irq, |
| 244 | IRQF_TRIGGER_RISING, "q6_wdog", NULL); |
| 245 | |
| 246 | if (ret < 0) { |
| 247 | pr_err("%s: Unable to request LPASS_Q6SS_WDOG_EXPIRED irq.", |
| 248 | __func__); |
| 249 | goto out; |
| 250 | } |
| 251 | ret = lpass_restart_init(); |
| 252 | if (ret < 0) { |
| 253 | pr_err("%s: Unable to reg with lpass ssr. (%d)\n", |
| 254 | __func__, ret); |
| 255 | goto out; |
| 256 | } |
Swaminathan Sathappan | 7107455 | 2011-09-20 10:09:31 -0700 | [diff] [blame] | 257 | |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 258 | lpass_ssr_8960.lpass_ramdump_dev = create_ramdump_device("lpass"); |
| 259 | |
| 260 | if (!lpass_ssr_8960.lpass_ramdump_dev) { |
| 261 | pr_err("%s: Unable to create ramdump device.\n", |
| 262 | __func__); |
| 263 | ret = -ENOMEM; |
| 264 | goto out; |
| 265 | } |
Sriranjan Srikantam | 6b2899c | 2011-10-10 16:28:49 -0700 | [diff] [blame] | 266 | ssr_notif_hdle = subsys_notif_register_notifier("riva", |
| 267 | &rnb); |
| 268 | if (IS_ERR(ssr_notif_hdle) < 0) { |
| 269 | ret = PTR_ERR(ssr_notif_hdle); |
| 270 | pr_err("%s: subsys_register_notifier for Riva: err = %d\n", |
| 271 | __func__, ret); |
Sriranjan Srikantam | 6b2899c | 2011-10-10 16:28:49 -0700 | [diff] [blame] | 272 | free_irq(LPASS_Q6SS_WDOG_EXPIRED, NULL); |
| 273 | goto out; |
| 274 | } |
| 275 | |
Sriranjan Srikantam | 3d907a6 | 2011-10-11 12:51:25 -0700 | [diff] [blame] | 276 | ssr_modem_notif_hdle = subsys_notif_register_notifier("modem", |
| 277 | &mnb); |
| 278 | if (IS_ERR(ssr_modem_notif_hdle) < 0) { |
| 279 | ret = PTR_ERR(ssr_modem_notif_hdle); |
| 280 | pr_err("%s: subsys_register_notifier for Modem: err = %d\n", |
| 281 | __func__, ret); |
| 282 | subsys_notif_unregister_notifier(ssr_notif_hdle, &rnb); |
Sriranjan Srikantam | 3d907a6 | 2011-10-11 12:51:25 -0700 | [diff] [blame] | 283 | free_irq(LPASS_Q6SS_WDOG_EXPIRED, NULL); |
| 284 | goto out; |
| 285 | } |
| 286 | |
Rohit Vaswani | 56dd22a | 2011-11-11 16:21:28 -0800 | [diff] [blame] | 287 | pr_info("%s: lpass SSR driver init'ed.\n", __func__); |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 288 | out: |
| 289 | return ret; |
| 290 | } |
| 291 | |
| 292 | static void __exit lpass_fatal_exit(void) |
| 293 | { |
Sriranjan Srikantam | 6b2899c | 2011-10-10 16:28:49 -0700 | [diff] [blame] | 294 | subsys_notif_unregister_notifier(ssr_notif_hdle, &rnb); |
Sriranjan Srikantam | 3d907a6 | 2011-10-11 12:51:25 -0700 | [diff] [blame] | 295 | subsys_notif_unregister_notifier(ssr_modem_notif_hdle, &mnb); |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 296 | subsys_unregister(lpass_8960_dev); |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 297 | free_irq(LPASS_Q6SS_WDOG_EXPIRED, NULL); |
| 298 | } |
| 299 | |
| 300 | module_init(lpass_fatal_init); |
| 301 | module_exit(lpass_fatal_exit); |
| 302 | |
| 303 | MODULE_LICENSE("GPL v2"); |