Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* 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> |
Stepan Moskovchenko | 6f59473 | 2011-09-20 16:51:47 -0700 | [diff] [blame] | 30 | #include <mach/socinfo.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 31 | |
| 32 | #include "smd_private.h" |
| 33 | #include "modem_notifier.h" |
| 34 | #include "ramdump.h" |
| 35 | |
| 36 | static int crash_shutdown; |
| 37 | |
| 38 | static void modem_sw_fatal_fn(struct work_struct *work) |
| 39 | { |
| 40 | uint32_t panic_smsm_states = SMSM_RESET | SMSM_SYSTEM_DOWNLOAD; |
| 41 | uint32_t reset_smsm_states = SMSM_SYSTEM_REBOOT_USR | |
| 42 | SMSM_SYSTEM_PWRDWN_USR; |
| 43 | uint32_t modem_state; |
| 44 | |
| 45 | pr_err("Watchdog bite received from modem SW!\n"); |
| 46 | |
| 47 | modem_state = smsm_get_state(SMSM_MODEM_STATE); |
| 48 | |
| 49 | if (modem_state & panic_smsm_states) { |
| 50 | |
| 51 | pr_err("Modem SMSM state changed to SMSM_RESET.\n" |
| 52 | "Probable err_fatal on the modem. " |
| 53 | "Calling subsystem restart...\n"); |
| 54 | subsystem_restart("modem"); |
| 55 | |
| 56 | } else if (modem_state & reset_smsm_states) { |
| 57 | |
| 58 | pr_err("%s: User-invoked system reset/powerdown. " |
| 59 | "Resetting the SoC now.\n", |
| 60 | __func__); |
| 61 | kernel_restart(NULL); |
| 62 | } else { |
| 63 | /* TODO: Bus unlock code/sequence goes _here_ */ |
| 64 | subsystem_restart("modem"); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | static void modem_fw_fatal_fn(struct work_struct *work) |
| 69 | { |
| 70 | pr_err("Watchdog bite received from modem FW!\n"); |
| 71 | subsystem_restart("modem"); |
| 72 | } |
| 73 | |
| 74 | static DECLARE_WORK(modem_sw_fatal_work, modem_sw_fatal_fn); |
| 75 | static DECLARE_WORK(modem_fw_fatal_work, modem_fw_fatal_fn); |
| 76 | |
| 77 | static void smsm_state_cb(void *data, uint32_t old_state, uint32_t new_state) |
| 78 | { |
| 79 | /* Ignore if we're the one that set SMSM_RESET */ |
| 80 | if (crash_shutdown) |
| 81 | return; |
| 82 | |
| 83 | if (new_state & SMSM_RESET) { |
| 84 | pr_err("Modem SMSM state changed to SMSM_RESET.\n" |
| 85 | "Probable err_fatal on the modem. " |
| 86 | "Calling subsystem restart...\n"); |
| 87 | subsystem_restart("modem"); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | static int modem_shutdown(const struct subsys_data *subsys) |
| 92 | { |
Vikram Mulukutla | 976ff0a | 2011-08-31 12:06:53 -0700 | [diff] [blame] | 93 | int smsm_notif_unregistered = 0; |
| 94 | |
| 95 | if (!(smsm_get_state(SMSM_MODEM_STATE) & SMSM_RESET)) { |
| 96 | smsm_state_cb_deregister(SMSM_MODEM_STATE, SMSM_RESET, |
| 97 | smsm_state_cb, 0); |
| 98 | smsm_notif_unregistered = 1; |
| 99 | smsm_reset_modem(SMSM_RESET); |
| 100 | } |
| 101 | |
| 102 | pil_force_shutdown("modem"); |
Saravana Kannan | 0dcf474 | 2011-09-21 17:19:17 -0700 | [diff] [blame^] | 103 | pil_force_shutdown("modem_fw"); |
Vikram Mulukutla | 976ff0a | 2011-08-31 12:06:53 -0700 | [diff] [blame] | 104 | disable_irq_nosync(Q6FW_WDOG_EXPIRED_IRQ); |
| 105 | disable_irq_nosync(Q6SW_WDOG_EXPIRED_IRQ); |
| 106 | |
| 107 | if (smsm_notif_unregistered) |
| 108 | smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_RESET, |
| 109 | smsm_state_cb, 0); |
| 110 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static int modem_powerup(const struct subsys_data *subsys) |
| 115 | { |
Saravana Kannan | 0dcf474 | 2011-09-21 17:19:17 -0700 | [diff] [blame^] | 116 | pil_force_boot("modem_fw"); |
Vikram Mulukutla | 976ff0a | 2011-08-31 12:06:53 -0700 | [diff] [blame] | 117 | pil_force_boot("modem"); |
| 118 | enable_irq(Q6FW_WDOG_EXPIRED_IRQ); |
| 119 | enable_irq(Q6SW_WDOG_EXPIRED_IRQ); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | void modem_crash_shutdown(const struct subsys_data *subsys) |
| 124 | { |
| 125 | crash_shutdown = 1; |
| 126 | smsm_reset_modem(SMSM_RESET); |
| 127 | } |
| 128 | |
| 129 | int modem_ramdump(int enable, const struct subsys_data *subsys) |
| 130 | { |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static irqreturn_t modem_wdog_bite_irq(int irq, void *dev_id) |
| 135 | { |
| 136 | int ret; |
| 137 | |
| 138 | switch (irq) { |
| 139 | |
| 140 | case Q6SW_WDOG_EXPIRED_IRQ: |
| 141 | ret = schedule_work(&modem_sw_fatal_work); |
| 142 | disable_irq_nosync(Q6SW_WDOG_EXPIRED_IRQ); |
Vikram Mulukutla | 976ff0a | 2011-08-31 12:06:53 -0700 | [diff] [blame] | 143 | disable_irq_nosync(Q6FW_WDOG_EXPIRED_IRQ); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 144 | break; |
| 145 | case Q6FW_WDOG_EXPIRED_IRQ: |
| 146 | ret = schedule_work(&modem_fw_fatal_work); |
Vikram Mulukutla | 976ff0a | 2011-08-31 12:06:53 -0700 | [diff] [blame] | 147 | disable_irq_nosync(Q6SW_WDOG_EXPIRED_IRQ); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 148 | disable_irq_nosync(Q6FW_WDOG_EXPIRED_IRQ); |
| 149 | break; |
| 150 | break; |
| 151 | |
| 152 | default: |
| 153 | pr_err("%s: Unknown IRQ!\n", __func__); |
| 154 | } |
| 155 | |
| 156 | return IRQ_HANDLED; |
| 157 | } |
| 158 | |
| 159 | static struct subsys_data modem_8960 = { |
| 160 | .name = "modem", |
| 161 | .shutdown = modem_shutdown, |
| 162 | .powerup = modem_powerup, |
| 163 | .ramdump = modem_ramdump, |
| 164 | .crash_shutdown = modem_crash_shutdown |
| 165 | }; |
| 166 | |
| 167 | static int modem_subsystem_restart_init(void) |
| 168 | { |
| 169 | return ssr_register_subsystem(&modem_8960); |
| 170 | } |
| 171 | |
| 172 | static int modem_debug_set(void *data, u64 val) |
| 173 | { |
Vikram Mulukutla | 976ff0a | 2011-08-31 12:06:53 -0700 | [diff] [blame] | 174 | if (val == 1) |
| 175 | subsystem_restart("modem"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | static int modem_debug_get(void *data, u64 *val) |
| 181 | { |
| 182 | *val = 0; |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | DEFINE_SIMPLE_ATTRIBUTE(modem_debug_fops, modem_debug_get, modem_debug_set, |
| 187 | "%llu\n"); |
| 188 | |
| 189 | static int modem_debugfs_init(void) |
| 190 | { |
| 191 | struct dentry *dent; |
| 192 | dent = debugfs_create_dir("modem_debug", 0); |
| 193 | |
| 194 | if (IS_ERR(dent)) |
| 195 | return PTR_ERR(dent); |
| 196 | |
| 197 | debugfs_create_file("reset_modem", 0644, dent, NULL, |
| 198 | &modem_debug_fops); |
| 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | static int __init modem_8960_init(void) |
| 203 | { |
| 204 | int ret; |
| 205 | |
Stepan Moskovchenko | 6f59473 | 2011-09-20 16:51:47 -0700 | [diff] [blame] | 206 | if (!cpu_is_msm8960()) |
| 207 | return -ENODEV; |
| 208 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 209 | ret = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_RESET, |
| 210 | smsm_state_cb, 0); |
| 211 | |
| 212 | if (ret < 0) |
| 213 | pr_err("%s: Unable to register SMSM callback! (%d)\n", |
| 214 | __func__, ret); |
| 215 | |
| 216 | ret = request_irq(Q6FW_WDOG_EXPIRED_IRQ, modem_wdog_bite_irq, |
| 217 | IRQF_TRIGGER_RISING, "modem_wdog_fw", NULL); |
| 218 | |
| 219 | if (ret < 0) { |
| 220 | pr_err("%s: Unable to request q6fw watchdog IRQ. (%d)\n", |
| 221 | __func__, ret); |
| 222 | goto out; |
| 223 | } |
| 224 | |
| 225 | ret = request_irq(Q6SW_WDOG_EXPIRED_IRQ, modem_wdog_bite_irq, |
| 226 | IRQF_TRIGGER_RISING, "modem_wdog_sw", NULL); |
| 227 | |
| 228 | if (ret < 0) { |
| 229 | pr_err("%s: Unable to request q6sw watchdog IRQ. (%d)\n", |
| 230 | __func__, ret); |
| 231 | disable_irq_nosync(Q6FW_WDOG_EXPIRED_IRQ); |
| 232 | goto out; |
| 233 | } |
| 234 | |
| 235 | ret = modem_subsystem_restart_init(); |
| 236 | |
| 237 | if (ret < 0) { |
| 238 | pr_err("%s: Unable to reg with subsystem restart. (%d)\n", |
| 239 | __func__, ret); |
| 240 | goto out; |
| 241 | } |
| 242 | |
| 243 | ret = modem_debugfs_init(); |
| 244 | |
| 245 | pr_info("%s: 8960 modem fatal driver init'ed.\n", __func__); |
| 246 | out: |
| 247 | return ret; |
| 248 | } |
| 249 | |
| 250 | module_init(modem_8960_init); |