Vikram Mulukutla | cc6c806 | 2012-01-19 13:10:34 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Vikram Mulukutla | ffa387e | 2011-09-13 15:14:35 -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/jiffies.h> |
| 19 | #include <linux/stringify.h> |
| 20 | #include <linux/delay.h> |
| 21 | #include <linux/module.h> |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame^] | 22 | #include <linux/err.h> |
Vikram Mulukutla | ffa387e | 2011-09-13 15:14:35 -0700 | [diff] [blame] | 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 | |
| 30 | #include "smd_private.h" |
| 31 | #include "modem_notifier.h" |
| 32 | #include "ramdump.h" |
| 33 | |
| 34 | #define Q6SS_WDOG_ENABLE 0x28882024 |
| 35 | #define Q6SS_SOFT_INTR_WAKEUP 0x288A001C |
| 36 | #define MODULE_NAME "lpass_8x60" |
| 37 | #define SCM_Q6_NMI_CMD 0x1 |
| 38 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame^] | 39 | static struct subsys_device *subsys_8x60_q6_dev; |
| 40 | |
Vikram Mulukutla | ffa387e | 2011-09-13 15:14:35 -0700 | [diff] [blame] | 41 | /* Subsystem restart: QDSP6 data, functions */ |
| 42 | static void *q6_ramdump_dev; |
| 43 | static void q6_fatal_fn(struct work_struct *); |
| 44 | static DECLARE_WORK(q6_fatal_work, q6_fatal_fn); |
Vikram Mulukutla | cc6c806 | 2012-01-19 13:10:34 -0800 | [diff] [blame] | 45 | static void __iomem *q6_wakeup_intr; |
Vikram Mulukutla | ffa387e | 2011-09-13 15:14:35 -0700 | [diff] [blame] | 46 | |
| 47 | static void q6_fatal_fn(struct work_struct *work) |
| 48 | { |
| 49 | pr_err("%s: Watchdog bite received from Q6!\n", MODULE_NAME); |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame^] | 50 | subsystem_restart_dev(subsys_8x60_q6_dev); |
Vikram Mulukutla | ffa387e | 2011-09-13 15:14:35 -0700 | [diff] [blame] | 51 | enable_irq(LPASS_Q6SS_WDOG_EXPIRED); |
| 52 | } |
| 53 | |
| 54 | static void send_q6_nmi(void) |
| 55 | { |
| 56 | /* Send NMI to QDSP6 via an SCM call. */ |
Vikram Mulukutla | cc6c806 | 2012-01-19 13:10:34 -0800 | [diff] [blame] | 57 | scm_call_atomic1(SCM_SVC_UTIL, SCM_Q6_NMI_CMD, 0x1); |
Vikram Mulukutla | ffa387e | 2011-09-13 15:14:35 -0700 | [diff] [blame] | 58 | |
| 59 | /* Wakeup the Q6 */ |
Vikram Mulukutla | cc6c806 | 2012-01-19 13:10:34 -0800 | [diff] [blame] | 60 | if (q6_wakeup_intr) |
| 61 | writel_relaxed(0x2000, q6_wakeup_intr); |
| 62 | else |
| 63 | pr_warn("lpass-8660: Unable to send wakeup interrupt to Q6.\n"); |
Vikram Mulukutla | ffa387e | 2011-09-13 15:14:35 -0700 | [diff] [blame] | 64 | |
| 65 | /* Q6 requires atleast 100ms to dump caches etc.*/ |
Vikram Mulukutla | cc6c806 | 2012-01-19 13:10:34 -0800 | [diff] [blame] | 66 | mdelay(100); |
Vikram Mulukutla | ffa387e | 2011-09-13 15:14:35 -0700 | [diff] [blame] | 67 | |
| 68 | pr_info("subsystem-fatal-8x60: Q6 NMI was sent.\n"); |
| 69 | } |
| 70 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame^] | 71 | int subsys_q6_shutdown(const struct subsys_desc *crashed_subsys) |
Vikram Mulukutla | ffa387e | 2011-09-13 15:14:35 -0700 | [diff] [blame] | 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 | |
Vikram Mulukutla | ffa387e | 2011-09-13 15:14:35 -0700 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame^] | 88 | int subsys_q6_powerup(const struct subsys_desc *crashed_subsys) |
Vikram Mulukutla | ffa387e | 2011-09-13 15:14:35 -0700 | [diff] [blame] | 89 | { |
| 90 | int ret = pil_force_boot("q6"); |
| 91 | enable_irq(LPASS_Q6SS_WDOG_EXPIRED); |
| 92 | return ret; |
| 93 | } |
| 94 | |
| 95 | /* FIXME: Get address, size from PIL */ |
| 96 | static struct ramdump_segment q6_segments[] = { {0x46700000, 0x47F00000 - |
| 97 | 0x46700000}, {0x28400000, 0x12800} }; |
| 98 | static int subsys_q6_ramdump(int enable, |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame^] | 99 | const struct subsys_desc *crashed_subsys) |
Vikram Mulukutla | ffa387e | 2011-09-13 15:14:35 -0700 | [diff] [blame] | 100 | { |
| 101 | if (enable) |
| 102 | return do_ramdump(q6_ramdump_dev, q6_segments, |
| 103 | ARRAY_SIZE(q6_segments)); |
| 104 | else |
| 105 | return 0; |
| 106 | } |
| 107 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame^] | 108 | void subsys_q6_crash_shutdown(const struct subsys_desc *crashed_subsys) |
Vikram Mulukutla | ffa387e | 2011-09-13 15:14:35 -0700 | [diff] [blame] | 109 | { |
| 110 | send_q6_nmi(); |
| 111 | } |
| 112 | |
| 113 | static irqreturn_t lpass_wdog_bite_irq(int irq, void *dev_id) |
| 114 | { |
| 115 | int ret; |
| 116 | |
| 117 | ret = schedule_work(&q6_fatal_work); |
| 118 | disable_irq_nosync(LPASS_Q6SS_WDOG_EXPIRED); |
| 119 | |
| 120 | return IRQ_HANDLED; |
| 121 | } |
| 122 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame^] | 123 | static struct subsys_desc subsys_8x60_q6 = { |
Vikram Mulukutla | ffa387e | 2011-09-13 15:14:35 -0700 | [diff] [blame] | 124 | .name = "lpass", |
| 125 | .shutdown = subsys_q6_shutdown, |
| 126 | .powerup = subsys_q6_powerup, |
| 127 | .ramdump = subsys_q6_ramdump, |
| 128 | .crash_shutdown = subsys_q6_crash_shutdown |
| 129 | }; |
| 130 | |
| 131 | static void __exit lpass_fatal_exit(void) |
| 132 | { |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame^] | 133 | subsys_unregister(subsys_8x60_q6_dev); |
Vikram Mulukutla | cc6c806 | 2012-01-19 13:10:34 -0800 | [diff] [blame] | 134 | iounmap(q6_wakeup_intr); |
Vikram Mulukutla | ffa387e | 2011-09-13 15:14:35 -0700 | [diff] [blame] | 135 | free_irq(LPASS_Q6SS_WDOG_EXPIRED, NULL); |
| 136 | } |
| 137 | |
| 138 | static int __init lpass_fatal_init(void) |
| 139 | { |
| 140 | int ret; |
| 141 | |
| 142 | ret = request_irq(LPASS_Q6SS_WDOG_EXPIRED, lpass_wdog_bite_irq, |
| 143 | IRQF_TRIGGER_RISING, "q6_wdog", NULL); |
| 144 | |
| 145 | if (ret < 0) { |
| 146 | pr_err("%s: Unable to request LPASS_Q6SS_WDOG_EXPIRED irq.", |
| 147 | __func__); |
| 148 | goto out; |
| 149 | } |
| 150 | |
| 151 | q6_ramdump_dev = create_ramdump_device("lpass"); |
| 152 | |
| 153 | if (!q6_ramdump_dev) { |
| 154 | ret = -ENOMEM; |
| 155 | goto out; |
| 156 | } |
| 157 | |
Vikram Mulukutla | cc6c806 | 2012-01-19 13:10:34 -0800 | [diff] [blame] | 158 | q6_wakeup_intr = ioremap_nocache(Q6SS_SOFT_INTR_WAKEUP, 8); |
| 159 | |
| 160 | if (!q6_wakeup_intr) |
| 161 | pr_warn("lpass-8660: Unable to ioremap q6 wakeup address."); |
| 162 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame^] | 163 | subsys_8x60_q6_dev = subsys_register(&subsys_8x60_q6); |
| 164 | if (IS_ERR(subsys_8x60_q6_dev)) |
| 165 | ret = PTR_ERR(subsys_8x60_q6_dev); |
Vikram Mulukutla | ffa387e | 2011-09-13 15:14:35 -0700 | [diff] [blame] | 166 | out: |
| 167 | return ret; |
| 168 | } |
| 169 | |
| 170 | module_init(lpass_fatal_init); |
| 171 | module_exit(lpass_fatal_exit); |
| 172 | |