Duy Truong | e833aca | 2013-02-12 13:35:08 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -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 | |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 13 | #define pr_fmt(fmt) "subsys-restart: %s(): " fmt, __func__ |
| 14 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 15 | #include <linux/kernel.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/uaccess.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/fs.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 20 | #include <linux/delay.h> |
| 21 | #include <linux/list.h> |
| 22 | #include <linux/io.h> |
| 23 | #include <linux/kthread.h> |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 24 | #include <linux/time.h> |
Vikram Mulukutla | f6349ae | 2012-02-24 12:21:15 -0800 | [diff] [blame] | 25 | #include <linux/wakelock.h> |
| 26 | #include <linux/suspend.h> |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 27 | #include <linux/mutex.h> |
Stephen Boyd | c68ee64 | 2012-05-01 17:02:45 -0700 | [diff] [blame] | 28 | #include <linux/slab.h> |
Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 29 | #include <linux/spinlock.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 30 | |
| 31 | #include <asm/current.h> |
| 32 | |
| 33 | #include <mach/peripheral-loader.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 34 | #include <mach/socinfo.h> |
| 35 | #include <mach/subsystem_notif.h> |
| 36 | #include <mach/subsystem_restart.h> |
| 37 | |
| 38 | #include "smd_private.h" |
| 39 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 40 | struct subsys_soc_restart_order { |
| 41 | const char * const *subsystem_list; |
| 42 | int count; |
| 43 | |
| 44 | struct mutex shutdown_lock; |
| 45 | struct mutex powerup_lock; |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 46 | struct subsys_device *subsys_ptrs[]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 49 | struct restart_log { |
| 50 | struct timeval time; |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 51 | struct subsys_device *dev; |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 52 | struct list_head list; |
| 53 | }; |
| 54 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 55 | struct subsys_device { |
| 56 | struct subsys_desc *desc; |
| 57 | struct list_head list; |
Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 58 | struct wake_lock wake_lock; |
| 59 | char wlname[64]; |
| 60 | struct work_struct work; |
| 61 | spinlock_t restart_lock; |
Stephen Boyd | 77c2274 | 2012-07-24 18:46:45 -0700 | [diff] [blame] | 62 | int restart_count; |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 63 | |
| 64 | void *notify; |
| 65 | |
| 66 | struct mutex shutdown_lock; |
| 67 | struct mutex powerup_lock; |
| 68 | |
| 69 | void *restart_order; |
| 70 | }; |
| 71 | |
Jaeseong GIM | cbea936 | 2012-10-10 15:42:17 +0900 | [diff] [blame] | 72 | static int enable_ramdumps; |
Stephen Boyd | c68ee64 | 2012-05-01 17:02:45 -0700 | [diff] [blame] | 73 | module_param(enable_ramdumps, int, S_IRUGO | S_IWUSR); |
| 74 | |
Vikram Mulukutla | 69177e1 | 2012-03-21 20:51:43 -0700 | [diff] [blame] | 75 | struct workqueue_struct *ssr_wq; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 76 | |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 77 | static LIST_HEAD(restart_log_list); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 78 | static LIST_HEAD(subsystem_list); |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 79 | static DEFINE_MUTEX(subsystem_list_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 80 | static DEFINE_MUTEX(soc_order_reg_lock); |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 81 | static DEFINE_MUTEX(restart_log_mutex); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 82 | |
| 83 | /* SOC specific restart orders go here */ |
| 84 | |
| 85 | #define DEFINE_SINGLE_RESTART_ORDER(name, order) \ |
| 86 | static struct subsys_soc_restart_order __##name = { \ |
| 87 | .subsystem_list = order, \ |
| 88 | .count = ARRAY_SIZE(order), \ |
| 89 | .subsys_ptrs = {[ARRAY_SIZE(order)] = NULL} \ |
| 90 | }; \ |
| 91 | static struct subsys_soc_restart_order *name[] = { \ |
| 92 | &__##name, \ |
| 93 | } |
| 94 | |
| 95 | /* MSM 8x60 restart ordering info */ |
| 96 | static const char * const _order_8x60_all[] = { |
| 97 | "external_modem", "modem", "lpass" |
| 98 | }; |
| 99 | DEFINE_SINGLE_RESTART_ORDER(orders_8x60_all, _order_8x60_all); |
| 100 | |
| 101 | static const char * const _order_8x60_modems[] = {"external_modem", "modem"}; |
| 102 | DEFINE_SINGLE_RESTART_ORDER(orders_8x60_modems, _order_8x60_modems); |
| 103 | |
Ameya Thakur | 2c0d2f2 | 2012-06-15 15:48:20 -0700 | [diff] [blame] | 104 | /*SGLTE restart ordering info*/ |
| 105 | static const char * const order_8960_sglte[] = {"external_modem", |
| 106 | "modem"}; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 107 | |
Ameya Thakur | 2c0d2f2 | 2012-06-15 15:48:20 -0700 | [diff] [blame] | 108 | static struct subsys_soc_restart_order restart_orders_8960_fusion_sglte = { |
| 109 | .subsystem_list = order_8960_sglte, |
| 110 | .count = ARRAY_SIZE(order_8960_sglte), |
| 111 | .subsys_ptrs = {[ARRAY_SIZE(order_8960_sglte)] = NULL} |
| 112 | }; |
| 113 | |
Ameya Thakur | 2c0d2f2 | 2012-06-15 15:48:20 -0700 | [diff] [blame] | 114 | static struct subsys_soc_restart_order *restart_orders_8960_sglte[] = { |
| 115 | &restart_orders_8960_fusion_sglte, |
| 116 | }; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 117 | |
Joel King | e4f9890 | 2013-03-25 13:12:27 -0700 | [diff] [blame] | 118 | /* SGLTE2 restart ordering info*/ |
| 119 | static const char * const order_8064_sglte2[] = {"external_modem", |
| 120 | "external_modem_mdm"}; |
| 121 | |
| 122 | static struct subsys_soc_restart_order restart_orders_8064_fusion_sglte2 = { |
| 123 | .subsystem_list = order_8064_sglte2, |
| 124 | .count = ARRAY_SIZE(order_8064_sglte2), |
| 125 | .subsys_ptrs = {[ARRAY_SIZE(order_8064_sglte2)] = NULL} |
| 126 | }; |
| 127 | |
| 128 | static struct subsys_soc_restart_order *restart_orders_8064_sglte2[] = { |
| 129 | &restart_orders_8064_fusion_sglte2, |
| 130 | }; |
| 131 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 132 | /* These will be assigned to one of the sets above after |
| 133 | * runtime SoC identification. |
| 134 | */ |
| 135 | static struct subsys_soc_restart_order **restart_orders; |
| 136 | static int n_restart_orders; |
| 137 | |
Brian Muramatsu | 0f0df2f | 2012-08-01 23:30:40 -0700 | [diff] [blame] | 138 | static int restart_level = RESET_SUBSYS_INDEPENDENT; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 139 | |
| 140 | int get_restart_level() |
| 141 | { |
| 142 | return restart_level; |
| 143 | } |
| 144 | EXPORT_SYMBOL(get_restart_level); |
| 145 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 146 | static int restart_level_set(const char *val, struct kernel_param *kp) |
| 147 | { |
| 148 | int ret; |
| 149 | int old_val = restart_level; |
Joel King | 4e20429 | 2013-04-16 12:48:51 -0700 | [diff] [blame^] | 150 | int subtype; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 151 | |
Rohit Vaswani | 56dd22a | 2011-11-11 16:21:28 -0800 | [diff] [blame] | 152 | if (cpu_is_msm9615()) { |
| 153 | pr_err("Only Phase 1 subsystem restart is supported\n"); |
| 154 | return -EINVAL; |
| 155 | } |
| 156 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 157 | ret = param_set_int(val, kp); |
| 158 | if (ret) |
| 159 | return ret; |
| 160 | |
| 161 | switch (restart_level) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 162 | case RESET_SUBSYS_INDEPENDENT: |
Joel King | 4e20429 | 2013-04-16 12:48:51 -0700 | [diff] [blame^] | 163 | subtype = socinfo_get_platform_subtype(); |
| 164 | if ((subtype == PLATFORM_SUBTYPE_SGLTE) || |
| 165 | (subtype == PLATFORM_SUBTYPE_SGLTE2)) { |
Vikram Mulukutla | f68456d | 2012-07-27 15:14:10 -0700 | [diff] [blame] | 166 | pr_info("Phase 3 is currently unsupported. Using phase 2 instead.\n"); |
| 167 | restart_level = RESET_SUBSYS_COUPLED; |
| 168 | } |
| 169 | case RESET_SUBSYS_COUPLED: |
| 170 | case RESET_SOC: |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 171 | pr_info("Phase %d behavior activated.\n", restart_level); |
Stephen Boyd | c68ee64 | 2012-05-01 17:02:45 -0700 | [diff] [blame] | 172 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 173 | default: |
| 174 | restart_level = old_val; |
| 175 | return -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 176 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | module_param_call(restart_level, restart_level_set, param_get_int, |
| 181 | &restart_level, 0644); |
| 182 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 183 | static struct subsys_soc_restart_order * |
| 184 | update_restart_order(struct subsys_device *dev) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 185 | { |
| 186 | int i, j; |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 187 | struct subsys_soc_restart_order *order; |
| 188 | const char *name = dev->desc->name; |
| 189 | int len = SUBSYS_NAME_MAX_LENGTH; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 190 | |
| 191 | mutex_lock(&soc_order_reg_lock); |
| 192 | for (j = 0; j < n_restart_orders; j++) { |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 193 | order = restart_orders[j]; |
| 194 | for (i = 0; i < order->count; i++) { |
| 195 | if (!strncmp(order->subsystem_list[i], name, len)) { |
| 196 | order->subsys_ptrs[i] = dev; |
| 197 | goto found; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 198 | } |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 199 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 200 | } |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 201 | order = NULL; |
| 202 | found: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 203 | mutex_unlock(&soc_order_reg_lock); |
| 204 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 205 | return order; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 208 | static int max_restarts; |
| 209 | module_param(max_restarts, int, 0644); |
| 210 | |
| 211 | static long max_history_time = 3600; |
| 212 | module_param(max_history_time, long, 0644); |
| 213 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 214 | static void do_epoch_check(struct subsys_device *dev) |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 215 | { |
| 216 | int n = 0; |
Jordan Crouse | 75a25ca | 2011-09-09 12:49:57 -0600 | [diff] [blame] | 217 | struct timeval *time_first = NULL, *curr_time; |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 218 | struct restart_log *r_log, *temp; |
| 219 | static int max_restarts_check; |
| 220 | static long max_history_time_check; |
| 221 | |
| 222 | mutex_lock(&restart_log_mutex); |
| 223 | |
| 224 | max_restarts_check = max_restarts; |
| 225 | max_history_time_check = max_history_time; |
| 226 | |
| 227 | /* Check if epoch checking is enabled */ |
| 228 | if (!max_restarts_check) |
Vikram Mulukutla | 7a28909 | 2011-09-14 10:08:36 -0700 | [diff] [blame] | 229 | goto out; |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 230 | |
| 231 | r_log = kmalloc(sizeof(struct restart_log), GFP_KERNEL); |
Matt Wagantall | eecca34 | 2011-11-10 20:12:05 -0800 | [diff] [blame] | 232 | if (!r_log) |
| 233 | goto out; |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 234 | r_log->dev = dev; |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 235 | do_gettimeofday(&r_log->time); |
| 236 | curr_time = &r_log->time; |
| 237 | INIT_LIST_HEAD(&r_log->list); |
| 238 | |
| 239 | list_add_tail(&r_log->list, &restart_log_list); |
| 240 | |
| 241 | list_for_each_entry_safe(r_log, temp, &restart_log_list, list) { |
| 242 | |
| 243 | if ((curr_time->tv_sec - r_log->time.tv_sec) > |
| 244 | max_history_time_check) { |
| 245 | |
| 246 | pr_debug("Deleted node with restart_time = %ld\n", |
| 247 | r_log->time.tv_sec); |
| 248 | list_del(&r_log->list); |
| 249 | kfree(r_log); |
| 250 | continue; |
| 251 | } |
| 252 | if (!n) { |
| 253 | time_first = &r_log->time; |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 254 | pr_debug("Time_first: %ld\n", time_first->tv_sec); |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 255 | } |
| 256 | n++; |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 257 | pr_debug("Restart_time: %ld\n", r_log->time.tv_sec); |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Jordan Crouse | 75a25ca | 2011-09-09 12:49:57 -0600 | [diff] [blame] | 260 | if (time_first && n >= max_restarts_check) { |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 261 | if ((curr_time->tv_sec - time_first->tv_sec) < |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 262 | max_history_time_check) { |
Vikram Mulukutla | 0ad34f6 | 2013-01-22 11:01:13 -0800 | [diff] [blame] | 263 | panic("Subsystems have crashed %d times in less than "\ |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 264 | "%ld seconds!", max_restarts_check, |
| 265 | max_history_time_check); |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 266 | } |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Vikram Mulukutla | 7a28909 | 2011-09-14 10:08:36 -0700 | [diff] [blame] | 269 | out: |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 270 | mutex_unlock(&restart_log_mutex); |
| 271 | } |
| 272 | |
Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 273 | static void for_each_subsys_device(struct subsys_device **list, unsigned count, |
| 274 | void *data, void (*fn)(struct subsys_device *, void *)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 275 | { |
Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 276 | while (count--) { |
| 277 | struct subsys_device *dev = *list++; |
| 278 | if (!dev) |
| 279 | continue; |
| 280 | fn(dev, data); |
| 281 | } |
| 282 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 283 | |
Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 284 | static void __send_notification_to_order(struct subsys_device *dev, void *data) |
| 285 | { |
| 286 | enum subsys_notif_type type = (enum subsys_notif_type)data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 287 | |
Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 288 | subsys_notif_queue_notification(dev->notify, type); |
| 289 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 290 | |
Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 291 | static void send_notification_to_order(struct subsys_device **l, unsigned n, |
| 292 | enum subsys_notif_type t) |
| 293 | { |
| 294 | for_each_subsys_device(l, n, (void *)t, __send_notification_to_order); |
| 295 | } |
| 296 | |
| 297 | static void subsystem_shutdown(struct subsys_device *dev, void *data) |
| 298 | { |
| 299 | const char *name = dev->desc->name; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 300 | |
Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 301 | pr_info("[%p]: Shutting down %s\n", current, name); |
Brian Muramatsu | 0f0df2f | 2012-08-01 23:30:40 -0700 | [diff] [blame] | 302 | if (dev->desc->shutdown(dev->desc) < 0) { |
Vikram Mulukutla | 0ad34f6 | 2013-01-22 11:01:13 -0800 | [diff] [blame] | 303 | panic("subsys-restart: [%p]: Failed to shutdown %s!", |
Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 304 | current, name); |
Brian Muramatsu | 0f0df2f | 2012-08-01 23:30:40 -0700 | [diff] [blame] | 305 | } |
Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | static void subsystem_ramdump(struct subsys_device *dev, void *data) |
| 309 | { |
| 310 | const char *name = dev->desc->name; |
| 311 | |
| 312 | if (dev->desc->ramdump) |
| 313 | if (dev->desc->ramdump(enable_ramdumps, dev->desc) < 0) |
| 314 | pr_warn("%s[%p]: Ramdump failed.\n", name, current); |
| 315 | } |
| 316 | |
| 317 | static void subsystem_powerup(struct subsys_device *dev, void *data) |
| 318 | { |
| 319 | const char *name = dev->desc->name; |
| 320 | |
| 321 | pr_info("[%p]: Powering up %s\n", current, name); |
Brian Muramatsu | 0f0df2f | 2012-08-01 23:30:40 -0700 | [diff] [blame] | 322 | if (dev->desc->powerup(dev->desc) < 0) { |
Vikram Mulukutla | 0ad34f6 | 2013-01-22 11:01:13 -0800 | [diff] [blame] | 323 | panic("[%p]: Failed to powerup %s!", current, name); |
Brian Muramatsu | 0f0df2f | 2012-08-01 23:30:40 -0700 | [diff] [blame] | 324 | } |
Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 327 | static void subsystem_restart_wq_func(struct work_struct *work) |
| 328 | { |
Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 329 | struct subsys_device *dev = container_of(work, |
| 330 | struct subsys_device, work); |
Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 331 | struct subsys_device **list; |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 332 | struct subsys_desc *desc = dev->desc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 333 | struct subsys_soc_restart_order *soc_restart_order = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 334 | struct mutex *powerup_lock; |
| 335 | struct mutex *shutdown_lock; |
Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 336 | unsigned count; |
Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 337 | unsigned long flags; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 338 | |
Stephen Boyd | a82ee08 | 2012-06-21 12:35:49 -0700 | [diff] [blame] | 339 | if (restart_level != RESET_SUBSYS_INDEPENDENT) |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 340 | soc_restart_order = dev->restart_order; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 341 | |
Stephen Boyd | c68ee64 | 2012-05-01 17:02:45 -0700 | [diff] [blame] | 342 | /* |
| 343 | * It's OK to not take the registration lock at this point. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 344 | * This is because the subsystem list inside the relevant |
| 345 | * restart order is not being traversed. |
| 346 | */ |
| 347 | if (!soc_restart_order) { |
Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 348 | list = &dev; |
| 349 | count = 1; |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 350 | powerup_lock = &dev->powerup_lock; |
| 351 | shutdown_lock = &dev->shutdown_lock; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 352 | } else { |
Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 353 | list = soc_restart_order->subsys_ptrs; |
| 354 | count = soc_restart_order->count; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 355 | powerup_lock = &soc_restart_order->powerup_lock; |
| 356 | shutdown_lock = &soc_restart_order->shutdown_lock; |
| 357 | } |
| 358 | |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 359 | pr_debug("[%p]: Attempting to get shutdown lock!\n", current); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 360 | |
Stephen Boyd | c68ee64 | 2012-05-01 17:02:45 -0700 | [diff] [blame] | 361 | /* |
| 362 | * Try to acquire shutdown_lock. If this fails, these subsystems are |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 363 | * already being restarted - return. |
| 364 | */ |
Vikram Mulukutla | f6349ae | 2012-02-24 12:21:15 -0800 | [diff] [blame] | 365 | if (!mutex_trylock(shutdown_lock)) |
| 366 | goto out; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 367 | |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 368 | pr_debug("[%p]: Attempting to get powerup lock!\n", current); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 369 | |
Stephen Boyd | c68ee64 | 2012-05-01 17:02:45 -0700 | [diff] [blame] | 370 | /* |
| 371 | * Now that we've acquired the shutdown lock, either we're the first to |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 372 | * restart these subsystems or some other thread is doing the powerup |
| 373 | * sequence for these subsystems. In the latter case, panic and bail |
| 374 | * out, since a subsystem died in its powerup sequence. |
| 375 | */ |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 376 | if (!mutex_trylock(powerup_lock)) { |
Vikram Mulukutla | 0ad34f6 | 2013-01-22 11:01:13 -0800 | [diff] [blame] | 377 | panic("%s[%p]: Subsystem died during powerup!", |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 378 | __func__, current); |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 379 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 380 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 381 | do_epoch_check(dev); |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 382 | |
Stephen Boyd | c68ee64 | 2012-05-01 17:02:45 -0700 | [diff] [blame] | 383 | /* |
| 384 | * It's necessary to take the registration lock because the subsystem |
| 385 | * list in the SoC restart order will be traversed and it shouldn't be |
| 386 | * changed until _this_ restart sequence completes. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 387 | */ |
| 388 | mutex_lock(&soc_order_reg_lock); |
| 389 | |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 390 | pr_debug("[%p]: Starting restart sequence for %s\n", current, |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 391 | desc->name); |
Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 392 | send_notification_to_order(list, count, SUBSYS_BEFORE_SHUTDOWN); |
| 393 | for_each_subsys_device(list, count, NULL, subsystem_shutdown); |
| 394 | send_notification_to_order(list, count, SUBSYS_AFTER_SHUTDOWN); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 395 | |
Stephen Boyd | c68ee64 | 2012-05-01 17:02:45 -0700 | [diff] [blame] | 396 | /* |
| 397 | * Now that we've finished shutting down these subsystems, release the |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 398 | * shutdown lock. If a subsystem restart request comes in for a |
| 399 | * subsystem in _this_ restart order after the unlock below, and |
| 400 | * before the powerup lock is released, panic and bail out. |
| 401 | */ |
| 402 | mutex_unlock(shutdown_lock); |
| 403 | |
| 404 | /* Collect ram dumps for all subsystems in order here */ |
Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 405 | for_each_subsys_device(list, count, NULL, subsystem_ramdump); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 406 | |
Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 407 | send_notification_to_order(list, count, SUBSYS_BEFORE_POWERUP); |
| 408 | for_each_subsys_device(list, count, NULL, subsystem_powerup); |
| 409 | send_notification_to_order(list, count, SUBSYS_AFTER_POWERUP); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 410 | |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 411 | pr_info("[%p]: Restart sequence for %s completed.\n", |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 412 | current, desc->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 413 | |
| 414 | mutex_unlock(powerup_lock); |
| 415 | |
| 416 | mutex_unlock(&soc_order_reg_lock); |
| 417 | |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 418 | pr_debug("[%p]: Released powerup lock!\n", current); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 419 | |
Vikram Mulukutla | f6349ae | 2012-02-24 12:21:15 -0800 | [diff] [blame] | 420 | out: |
Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 421 | spin_lock_irqsave(&dev->restart_lock, flags); |
Stephen Boyd | 77c2274 | 2012-07-24 18:46:45 -0700 | [diff] [blame] | 422 | dev->restart_count--; |
| 423 | if (!dev->restart_count) |
| 424 | wake_unlock(&dev->wake_lock); |
Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 425 | spin_unlock_irqrestore(&dev->restart_lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 428 | static void __subsystem_restart_dev(struct subsys_device *dev) |
Vikram Mulukutla | 922a4f1 | 2012-04-13 14:36:50 -0700 | [diff] [blame] | 429 | { |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 430 | struct subsys_desc *desc = dev->desc; |
Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 431 | unsigned long flags; |
Vikram Mulukutla | 922a4f1 | 2012-04-13 14:36:50 -0700 | [diff] [blame] | 432 | |
Stephen Boyd | 77c2274 | 2012-07-24 18:46:45 -0700 | [diff] [blame] | 433 | pr_debug("Restarting %s [level=%d]!\n", desc->name, restart_level); |
Vikram Mulukutla | 922a4f1 | 2012-04-13 14:36:50 -0700 | [diff] [blame] | 434 | |
Stephen Boyd | 77c2274 | 2012-07-24 18:46:45 -0700 | [diff] [blame] | 435 | spin_lock_irqsave(&dev->restart_lock, flags); |
| 436 | if (!dev->restart_count) |
Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 437 | wake_lock(&dev->wake_lock); |
Stephen Boyd | 77c2274 | 2012-07-24 18:46:45 -0700 | [diff] [blame] | 438 | dev->restart_count++; |
Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 439 | spin_unlock_irqrestore(&dev->restart_lock, flags); |
Stephen Boyd | 77c2274 | 2012-07-24 18:46:45 -0700 | [diff] [blame] | 440 | |
| 441 | if (!queue_work(ssr_wq, &dev->work)) { |
| 442 | spin_lock_irqsave(&dev->restart_lock, flags); |
| 443 | dev->restart_count--; |
| 444 | if (!dev->restart_count) |
| 445 | wake_unlock(&dev->wake_lock); |
| 446 | spin_unlock_irqrestore(&dev->restart_lock, flags); |
| 447 | } |
Vikram Mulukutla | 922a4f1 | 2012-04-13 14:36:50 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 450 | int subsystem_restart_dev(struct subsys_device *dev) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 451 | { |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 452 | const char *name = dev->desc->name; |
Vikram Mulukutla | 3944eff | 2012-10-29 18:43:02 -0700 | [diff] [blame] | 453 | |
| 454 | /* |
| 455 | * If a system reboot/shutdown is underway, ignore subsystem errors. |
| 456 | * However, print a message so that we know that a subsystem behaved |
| 457 | * unexpectedly here. |
| 458 | */ |
| 459 | if (system_state == SYSTEM_RESTART |
| 460 | || system_state == SYSTEM_POWER_OFF) { |
| 461 | pr_err("%s crashed during a system poweroff/shutdown.\n", name); |
| 462 | return -EBUSY; |
| 463 | } |
| 464 | |
Vikram Mulukutla | 3b24c8c | 2011-12-02 15:12:53 -0800 | [diff] [blame] | 465 | pr_info("Restart sequence requested for %s, restart_level = %d.\n", |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 466 | name, restart_level); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 467 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 468 | switch (restart_level) { |
| 469 | |
| 470 | case RESET_SUBSYS_COUPLED: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 471 | case RESET_SUBSYS_INDEPENDENT: |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 472 | __subsystem_restart_dev(dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 473 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 474 | case RESET_SOC: |
Ameya Thakur | 97d4114 | 2012-12-05 17:04:52 -0800 | [diff] [blame] | 475 | panic("subsys-restart: Resetting the SoC - %s crashed.", name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 476 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 477 | default: |
Ameya Thakur | 97d4114 | 2012-12-05 17:04:52 -0800 | [diff] [blame] | 478 | panic("subsys-restart: Unknown restart level!\n"); |
Stephen Boyd | c68ee64 | 2012-05-01 17:02:45 -0700 | [diff] [blame] | 479 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | return 0; |
| 483 | } |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 484 | EXPORT_SYMBOL(subsystem_restart_dev); |
| 485 | |
| 486 | int subsystem_restart(const char *name) |
| 487 | { |
| 488 | struct subsys_device *dev; |
| 489 | |
| 490 | mutex_lock(&subsystem_list_lock); |
| 491 | list_for_each_entry(dev, &subsystem_list, list) |
| 492 | if (!strncmp(dev->desc->name, name, SUBSYS_NAME_MAX_LENGTH)) |
| 493 | goto found; |
| 494 | dev = NULL; |
| 495 | found: |
| 496 | mutex_unlock(&subsystem_list_lock); |
| 497 | if (dev) |
| 498 | return subsystem_restart_dev(dev); |
| 499 | return -ENODEV; |
| 500 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 501 | EXPORT_SYMBOL(subsystem_restart); |
| 502 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 503 | struct subsys_device *subsys_register(struct subsys_desc *desc) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 504 | { |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 505 | struct subsys_device *dev; |
Vikram Mulukutla | 705e689 | 2012-06-08 17:57:31 -0700 | [diff] [blame] | 506 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 507 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 508 | if (!dev) |
| 509 | return ERR_PTR(-ENOMEM); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 510 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 511 | dev->desc = desc; |
| 512 | dev->notify = subsys_notif_add_subsys(desc->name); |
| 513 | dev->restart_order = update_restart_order(dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 514 | |
Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 515 | snprintf(dev->wlname, sizeof(dev->wlname), "ssr(%s)", desc->name); |
| 516 | wake_lock_init(&dev->wake_lock, WAKE_LOCK_SUSPEND, dev->wlname); |
| 517 | INIT_WORK(&dev->work, subsystem_restart_wq_func); |
| 518 | spin_lock_init(&dev->restart_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 519 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 520 | mutex_init(&dev->shutdown_lock); |
| 521 | mutex_init(&dev->powerup_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 522 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 523 | mutex_lock(&subsystem_list_lock); |
| 524 | list_add(&dev->list, &subsystem_list); |
| 525 | mutex_unlock(&subsystem_list_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 526 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 527 | return dev; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 528 | } |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 529 | EXPORT_SYMBOL(subsys_register); |
| 530 | |
| 531 | void subsys_unregister(struct subsys_device *dev) |
| 532 | { |
| 533 | if (IS_ERR_OR_NULL(dev)) |
| 534 | return; |
| 535 | mutex_lock(&subsystem_list_lock); |
| 536 | list_del(&dev->list); |
| 537 | mutex_unlock(&subsystem_list_lock); |
Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 538 | wake_lock_destroy(&dev->wake_lock); |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 539 | kfree(dev); |
| 540 | } |
| 541 | EXPORT_SYMBOL(subsys_unregister); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 542 | |
Vikram Mulukutla | 2a7ea7e | 2011-09-06 11:38:47 -0700 | [diff] [blame] | 543 | static int ssr_panic_handler(struct notifier_block *this, |
| 544 | unsigned long event, void *ptr) |
| 545 | { |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 546 | struct subsys_device *dev; |
Vikram Mulukutla | 2a7ea7e | 2011-09-06 11:38:47 -0700 | [diff] [blame] | 547 | |
Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 548 | list_for_each_entry(dev, &subsystem_list, list) |
| 549 | if (dev->desc->crash_shutdown) |
| 550 | dev->desc->crash_shutdown(dev->desc); |
Vikram Mulukutla | 2a7ea7e | 2011-09-06 11:38:47 -0700 | [diff] [blame] | 551 | return NOTIFY_DONE; |
| 552 | } |
| 553 | |
| 554 | static struct notifier_block panic_nb = { |
| 555 | .notifier_call = ssr_panic_handler, |
| 556 | }; |
| 557 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 558 | static int __init ssr_init_soc_restart_orders(void) |
| 559 | { |
| 560 | int i; |
| 561 | |
Vikram Mulukutla | 2a7ea7e | 2011-09-06 11:38:47 -0700 | [diff] [blame] | 562 | atomic_notifier_chain_register(&panic_notifier_list, |
| 563 | &panic_nb); |
| 564 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 565 | if (cpu_is_msm8x60()) { |
| 566 | for (i = 0; i < ARRAY_SIZE(orders_8x60_all); i++) { |
| 567 | mutex_init(&orders_8x60_all[i]->powerup_lock); |
| 568 | mutex_init(&orders_8x60_all[i]->shutdown_lock); |
| 569 | } |
| 570 | |
| 571 | for (i = 0; i < ARRAY_SIZE(orders_8x60_modems); i++) { |
| 572 | mutex_init(&orders_8x60_modems[i]->powerup_lock); |
| 573 | mutex_init(&orders_8x60_modems[i]->shutdown_lock); |
| 574 | } |
| 575 | |
| 576 | restart_orders = orders_8x60_all; |
| 577 | n_restart_orders = ARRAY_SIZE(orders_8x60_all); |
| 578 | } |
| 579 | |
Vikram Mulukutla | f68456d | 2012-07-27 15:14:10 -0700 | [diff] [blame] | 580 | if (socinfo_get_platform_subtype() == PLATFORM_SUBTYPE_SGLTE) { |
| 581 | restart_orders = restart_orders_8960_sglte; |
| 582 | n_restart_orders = ARRAY_SIZE(restart_orders_8960_sglte); |
| 583 | } |
| 584 | |
Joel King | e4f9890 | 2013-03-25 13:12:27 -0700 | [diff] [blame] | 585 | if (socinfo_get_platform_subtype() == PLATFORM_SUBTYPE_SGLTE2) { |
| 586 | restart_orders = restart_orders_8064_sglte2; |
| 587 | n_restart_orders = ARRAY_SIZE(restart_orders_8064_sglte2); |
| 588 | } |
| 589 | |
Vikram Mulukutla | f68456d | 2012-07-27 15:14:10 -0700 | [diff] [blame] | 590 | for (i = 0; i < n_restart_orders; i++) { |
| 591 | mutex_init(&restart_orders[i]->powerup_lock); |
| 592 | mutex_init(&restart_orders[i]->shutdown_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | if (restart_orders == NULL || n_restart_orders < 1) { |
| 596 | WARN_ON(1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | static int __init subsys_restart_init(void) |
| 603 | { |
Vikram Mulukutla | 372e15a | 2013-01-22 10:51:17 -0800 | [diff] [blame] | 604 | restart_level = RESET_SOC; |
| 605 | |
Vikram Mulukutla | 99f84eff | 2012-09-10 19:25:32 -0700 | [diff] [blame] | 606 | ssr_wq = alloc_workqueue("ssr_wq", WQ_CPU_INTENSIVE, 0); |
Vikram Mulukutla | 0ad34f6 | 2013-01-22 11:01:13 -0800 | [diff] [blame] | 607 | if (!ssr_wq) |
| 608 | panic("%s: out of memory\n", __func__); |
Vikram Mulukutla | 69177e1 | 2012-03-21 20:51:43 -0700 | [diff] [blame] | 609 | |
Iliyan Malchev | a0899ce | 2012-06-29 15:28:25 -0700 | [diff] [blame] | 610 | return ssr_init_soc_restart_orders(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 611 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 612 | arch_initcall(subsys_restart_init); |
| 613 | |
| 614 | MODULE_DESCRIPTION("Subsystem Restart Driver"); |
| 615 | MODULE_LICENSE("GPL v2"); |