Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -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/delay.h> |
| 19 | #include <linux/module.h> |
| 20 | |
| 21 | #include <mach/irqs.h> |
| 22 | #include <mach/scm.h> |
| 23 | #include <mach/peripheral-loader.h> |
| 24 | #include <mach/subsystem_restart.h> |
| 25 | #include <mach/subsystem_notif.h> |
| 26 | |
| 27 | #include "smd_private.h" |
| 28 | #include "ramdump.h" |
| 29 | |
| 30 | #define SCM_Q6_NMI_CMD 0x1 |
| 31 | #define MODULE_NAME "lpass_8960" |
| 32 | #define Q6SS_SOFT_INTR_WAKEUP 0x28800024 |
| 33 | |
| 34 | /* Subsystem restart: QDSP6 data, functions */ |
| 35 | static void lpass_fatal_fn(struct work_struct *); |
| 36 | static DECLARE_WORK(lpass_fatal_work, lpass_fatal_fn); |
Swaminathan Sathappan | 7107455 | 2011-09-20 10:09:31 -0700 | [diff] [blame] | 37 | void __iomem *q6_wakeup_intr; |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 38 | struct lpass_ssr { |
| 39 | void *lpass_ramdump_dev; |
| 40 | } lpass_ssr; |
| 41 | |
| 42 | static struct lpass_ssr lpass_ssr_8960; |
Swaminathan Sathappan | fc137ec | 2011-08-16 15:18:41 -0700 | [diff] [blame^] | 43 | static int q6_crash_shutdown; |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 44 | |
| 45 | static void lpass_fatal_fn(struct work_struct *work) |
| 46 | { |
Swaminathan Sathappan | fc137ec | 2011-08-16 15:18:41 -0700 | [diff] [blame^] | 47 | pr_err("%s %s: Watchdog bite received from Q6!\n", MODULE_NAME, |
| 48 | __func__); |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 49 | subsystem_restart("lpass"); |
| 50 | } |
| 51 | |
Swaminathan Sathappan | fc137ec | 2011-08-16 15:18:41 -0700 | [diff] [blame^] | 52 | static void lpass_smsm_state_cb(void *data, uint32_t old_state, |
| 53 | uint32_t new_state) |
| 54 | { |
| 55 | /* Ignore if we're the one that set SMSM_RESET */ |
| 56 | if (q6_crash_shutdown) |
| 57 | return; |
| 58 | |
| 59 | if (new_state & SMSM_RESET) { |
| 60 | pr_err("%s: LPASS SMSM state changed to SMSM_RESET," |
| 61 | " new_state = 0x%x, old_state = 0x%x\n", __func__, |
| 62 | new_state, old_state); |
| 63 | subsystem_restart("lpass"); |
| 64 | } |
| 65 | } |
| 66 | |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 67 | static void send_q6_nmi(void) |
| 68 | { |
| 69 | /* Send NMI to QDSP6 via an SCM call. */ |
| 70 | uint32_t cmd = 0x1; |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 71 | |
| 72 | scm_call(SCM_SVC_UTIL, SCM_Q6_NMI_CMD, |
| 73 | &cmd, sizeof(cmd), NULL, 0); |
| 74 | |
| 75 | /* Wakeup the Q6 */ |
Swaminathan Sathappan | 7107455 | 2011-09-20 10:09:31 -0700 | [diff] [blame] | 76 | if (q6_wakeup_intr) |
| 77 | writel_relaxed(0x01, q6_wakeup_intr); |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 78 | mb(); |
| 79 | |
| 80 | /* Q6 requires worstcase 100ms to dump caches etc.*/ |
Swaminathan Sathappan | 7107455 | 2011-09-20 10:09:31 -0700 | [diff] [blame] | 81 | mdelay(100); |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 82 | pr_debug("%s: Q6 NMI was sent.\n", __func__); |
| 83 | } |
| 84 | |
| 85 | static int lpass_shutdown(const struct subsys_data *subsys) |
| 86 | { |
| 87 | send_q6_nmi(); |
| 88 | pil_force_shutdown("q6"); |
| 89 | disable_irq_nosync(LPASS_Q6SS_WDOG_EXPIRED); |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | static int lpass_powerup(const struct subsys_data *subsys) |
| 95 | { |
| 96 | int ret = pil_force_boot("q6"); |
| 97 | enable_irq(LPASS_Q6SS_WDOG_EXPIRED); |
| 98 | return ret; |
| 99 | } |
| 100 | /* RAM segments - address and size for 8960 */ |
| 101 | static struct ramdump_segment q6_segments[] = { {0x8da00000, 0x8f200000 - |
| 102 | 0x8da00000}, {0x28400000, 0x20000} }; |
| 103 | static int lpass_ramdump(int enable, const struct subsys_data *subsys) |
| 104 | { |
| 105 | pr_debug("%s: enable[%d]\n", __func__, enable); |
| 106 | if (enable) |
| 107 | return do_ramdump(lpass_ssr_8960.lpass_ramdump_dev, |
| 108 | q6_segments, |
| 109 | ARRAY_SIZE(q6_segments)); |
| 110 | else |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static void lpass_crash_shutdown(const struct subsys_data *subsys) |
| 115 | { |
Swaminathan Sathappan | fc137ec | 2011-08-16 15:18:41 -0700 | [diff] [blame^] | 116 | q6_crash_shutdown = 1; |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 117 | send_q6_nmi(); |
| 118 | } |
| 119 | |
| 120 | static irqreturn_t lpass_wdog_bite_irq(int irq, void *dev_id) |
| 121 | { |
| 122 | int ret; |
| 123 | |
| 124 | pr_debug("%s: rxed irq[0x%x]", __func__, irq); |
| 125 | disable_irq_nosync(LPASS_Q6SS_WDOG_EXPIRED); |
| 126 | ret = schedule_work(&lpass_fatal_work); |
| 127 | |
| 128 | return IRQ_HANDLED; |
| 129 | } |
| 130 | |
| 131 | static struct subsys_data lpass_8960 = { |
| 132 | .name = "lpass", |
| 133 | .shutdown = lpass_shutdown, |
| 134 | .powerup = lpass_powerup, |
| 135 | .ramdump = lpass_ramdump, |
| 136 | .crash_shutdown = lpass_crash_shutdown |
| 137 | }; |
| 138 | |
| 139 | static int __init lpass_restart_init(void) |
| 140 | { |
| 141 | return ssr_register_subsystem(&lpass_8960); |
| 142 | } |
| 143 | |
| 144 | static int __init lpass_fatal_init(void) |
| 145 | { |
| 146 | int ret; |
| 147 | |
Swaminathan Sathappan | fc137ec | 2011-08-16 15:18:41 -0700 | [diff] [blame^] | 148 | ret = smsm_state_cb_register(SMSM_Q6_STATE, SMSM_RESET, |
| 149 | lpass_smsm_state_cb, 0); |
| 150 | |
| 151 | if (ret < 0) |
| 152 | pr_err("%s: Unable to register SMSM callback! (%d)\n", |
| 153 | __func__, ret); |
| 154 | |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 155 | ret = request_irq(LPASS_Q6SS_WDOG_EXPIRED, lpass_wdog_bite_irq, |
| 156 | IRQF_TRIGGER_RISING, "q6_wdog", NULL); |
| 157 | |
| 158 | if (ret < 0) { |
| 159 | pr_err("%s: Unable to request LPASS_Q6SS_WDOG_EXPIRED irq.", |
| 160 | __func__); |
| 161 | goto out; |
| 162 | } |
| 163 | ret = lpass_restart_init(); |
| 164 | if (ret < 0) { |
| 165 | pr_err("%s: Unable to reg with lpass ssr. (%d)\n", |
| 166 | __func__, ret); |
| 167 | goto out; |
| 168 | } |
Swaminathan Sathappan | 7107455 | 2011-09-20 10:09:31 -0700 | [diff] [blame] | 169 | q6_wakeup_intr = ioremap_nocache(Q6SS_SOFT_INTR_WAKEUP, 8); |
| 170 | if (!q6_wakeup_intr) |
| 171 | pr_err("%s: Unable to request q6 wakeup interrupt\n", __func__); |
| 172 | |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 173 | lpass_ssr_8960.lpass_ramdump_dev = create_ramdump_device("lpass"); |
| 174 | |
| 175 | if (!lpass_ssr_8960.lpass_ramdump_dev) { |
| 176 | pr_err("%s: Unable to create ramdump device.\n", |
| 177 | __func__); |
| 178 | ret = -ENOMEM; |
| 179 | goto out; |
| 180 | } |
| 181 | pr_info("%s: 8960 lpass SSR driver init'ed.\n", __func__); |
| 182 | out: |
| 183 | return ret; |
| 184 | } |
| 185 | |
| 186 | static void __exit lpass_fatal_exit(void) |
| 187 | { |
Swaminathan Sathappan | 7107455 | 2011-09-20 10:09:31 -0700 | [diff] [blame] | 188 | iounmap(q6_wakeup_intr); |
Bharath Ramachandramurthy | ff061c7 | 2011-06-27 14:22:33 -0700 | [diff] [blame] | 189 | free_irq(LPASS_Q6SS_WDOG_EXPIRED, NULL); |
| 190 | } |
| 191 | |
| 192 | module_init(lpass_fatal_init); |
| 193 | module_exit(lpass_fatal_exit); |
| 194 | |
| 195 | MODULE_LICENSE("GPL v2"); |