Vikram Mulukutla | ffa387e | 2011-09-13 15:14:35 -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 | |
| 23 | #include <mach/irqs.h> |
| 24 | #include <mach/scm.h> |
| 25 | #include <mach/peripheral-loader.h> |
| 26 | #include <mach/subsystem_restart.h> |
| 27 | #include <mach/subsystem_notif.h> |
| 28 | |
| 29 | #include "smd_private.h" |
| 30 | #include "modem_notifier.h" |
| 31 | #include "ramdump.h" |
| 32 | |
| 33 | #define Q6SS_WDOG_ENABLE 0x28882024 |
| 34 | #define Q6SS_SOFT_INTR_WAKEUP 0x288A001C |
| 35 | #define MODULE_NAME "lpass_8x60" |
| 36 | #define SCM_Q6_NMI_CMD 0x1 |
| 37 | |
| 38 | /* Subsystem restart: QDSP6 data, functions */ |
| 39 | static void *q6_ramdump_dev; |
| 40 | static void q6_fatal_fn(struct work_struct *); |
| 41 | static DECLARE_WORK(q6_fatal_work, q6_fatal_fn); |
| 42 | |
| 43 | static void q6_fatal_fn(struct work_struct *work) |
| 44 | { |
| 45 | pr_err("%s: Watchdog bite received from Q6!\n", MODULE_NAME); |
| 46 | subsystem_restart("lpass"); |
| 47 | enable_irq(LPASS_Q6SS_WDOG_EXPIRED); |
| 48 | } |
| 49 | |
| 50 | static void send_q6_nmi(void) |
| 51 | { |
| 52 | /* Send NMI to QDSP6 via an SCM call. */ |
| 53 | uint32_t cmd = 0x1; |
| 54 | void __iomem *q6_wakeup_intr; |
| 55 | |
| 56 | scm_call(SCM_SVC_UTIL, SCM_Q6_NMI_CMD, |
| 57 | &cmd, sizeof(cmd), NULL, 0); |
| 58 | |
| 59 | /* Wakeup the Q6 */ |
| 60 | q6_wakeup_intr = ioremap_nocache(Q6SS_SOFT_INTR_WAKEUP, 8); |
| 61 | writel_relaxed(0x2000, q6_wakeup_intr); |
| 62 | iounmap(q6_wakeup_intr); |
| 63 | mb(); |
| 64 | |
| 65 | /* Q6 requires atleast 100ms to dump caches etc.*/ |
| 66 | msleep(100); |
| 67 | |
| 68 | pr_info("subsystem-fatal-8x60: Q6 NMI was sent.\n"); |
| 69 | } |
| 70 | |
| 71 | int subsys_q6_shutdown(const struct subsys_data *crashed_subsys) |
| 72 | { |
| 73 | void __iomem *q6_wdog_addr = |
| 74 | ioremap_nocache(Q6SS_WDOG_ENABLE, 8); |
| 75 | |
| 76 | send_q6_nmi(); |
| 77 | writel_relaxed(0x0, q6_wdog_addr); |
| 78 | /* The write needs to go through before the q6 is shutdown. */ |
| 79 | mb(); |
| 80 | iounmap(q6_wdog_addr); |
| 81 | |
| 82 | pil_force_shutdown("q6"); |
| 83 | disable_irq_nosync(LPASS_Q6SS_WDOG_EXPIRED); |
| 84 | |
| 85 | if (get_restart_level() == RESET_SUBSYS_MIXED) |
| 86 | smsm_reset_modem(SMSM_RESET); |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | int subsys_q6_powerup(const struct subsys_data *crashed_subsys) |
| 92 | { |
| 93 | int ret = pil_force_boot("q6"); |
| 94 | enable_irq(LPASS_Q6SS_WDOG_EXPIRED); |
| 95 | return ret; |
| 96 | } |
| 97 | |
| 98 | /* FIXME: Get address, size from PIL */ |
| 99 | static struct ramdump_segment q6_segments[] = { {0x46700000, 0x47F00000 - |
| 100 | 0x46700000}, {0x28400000, 0x12800} }; |
| 101 | static int subsys_q6_ramdump(int enable, |
| 102 | const struct subsys_data *crashed_subsys) |
| 103 | { |
| 104 | if (enable) |
| 105 | return do_ramdump(q6_ramdump_dev, q6_segments, |
| 106 | ARRAY_SIZE(q6_segments)); |
| 107 | else |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | void subsys_q6_crash_shutdown(const struct subsys_data *crashed_subsys) |
| 112 | { |
| 113 | send_q6_nmi(); |
| 114 | } |
| 115 | |
| 116 | static irqreturn_t lpass_wdog_bite_irq(int irq, void *dev_id) |
| 117 | { |
| 118 | int ret; |
| 119 | |
| 120 | ret = schedule_work(&q6_fatal_work); |
| 121 | disable_irq_nosync(LPASS_Q6SS_WDOG_EXPIRED); |
| 122 | |
| 123 | return IRQ_HANDLED; |
| 124 | } |
| 125 | |
| 126 | static struct subsys_data subsys_8x60_q6 = { |
| 127 | .name = "lpass", |
| 128 | .shutdown = subsys_q6_shutdown, |
| 129 | .powerup = subsys_q6_powerup, |
| 130 | .ramdump = subsys_q6_ramdump, |
| 131 | .crash_shutdown = subsys_q6_crash_shutdown |
| 132 | }; |
| 133 | |
| 134 | static void __exit lpass_fatal_exit(void) |
| 135 | { |
| 136 | free_irq(LPASS_Q6SS_WDOG_EXPIRED, NULL); |
| 137 | } |
| 138 | |
| 139 | static int __init lpass_fatal_init(void) |
| 140 | { |
| 141 | int ret; |
| 142 | |
| 143 | ret = request_irq(LPASS_Q6SS_WDOG_EXPIRED, lpass_wdog_bite_irq, |
| 144 | IRQF_TRIGGER_RISING, "q6_wdog", NULL); |
| 145 | |
| 146 | if (ret < 0) { |
| 147 | pr_err("%s: Unable to request LPASS_Q6SS_WDOG_EXPIRED irq.", |
| 148 | __func__); |
| 149 | goto out; |
| 150 | } |
| 151 | |
| 152 | q6_ramdump_dev = create_ramdump_device("lpass"); |
| 153 | |
| 154 | if (!q6_ramdump_dev) { |
| 155 | ret = -ENOMEM; |
| 156 | goto out; |
| 157 | } |
| 158 | |
| 159 | ret = ssr_register_subsystem(&subsys_8x60_q6); |
| 160 | out: |
| 161 | return ret; |
| 162 | } |
| 163 | |
| 164 | module_init(lpass_fatal_init); |
| 165 | module_exit(lpass_fatal_exit); |
| 166 | |