| .. | .. |
|---|
| 27 | 27 | #include <linux/notifier.h> |
|---|
| 28 | 28 | #include <linux/suspend.h> |
|---|
| 29 | 29 | #include <linux/slab.h> |
|---|
| 30 | | -#if defined(CONFIG_ROCKCHIP_SIP) |
|---|
| 31 | | -#include <linux/rockchip/rockchip_sip.h> |
|---|
| 32 | | -#endif |
|---|
| 33 | 30 | |
|---|
| 34 | 31 | /* |
|---|
| 35 | 32 | * struct wakeup_irq_node - stores data and relationships for IRQs logged as |
|---|
| .. | .. |
|---|
| 44 | 41 | const char *irq_name; |
|---|
| 45 | 42 | }; |
|---|
| 46 | 43 | |
|---|
| 47 | | -static DEFINE_RAW_SPINLOCK(wakeup_reason_lock); |
|---|
| 44 | +enum wakeup_reason_flag { |
|---|
| 45 | + RESUME_NONE = 0, |
|---|
| 46 | + RESUME_IRQ, |
|---|
| 47 | + RESUME_ABORT, |
|---|
| 48 | + RESUME_ABNORMAL, |
|---|
| 49 | +}; |
|---|
| 50 | + |
|---|
| 51 | +static DEFINE_SPINLOCK(wakeup_reason_lock); |
|---|
| 48 | 52 | |
|---|
| 49 | 53 | static LIST_HEAD(leaf_irqs); /* kept in ascending IRQ sorted order */ |
|---|
| 50 | 54 | static LIST_HEAD(parent_irqs); /* unordered */ |
|---|
| .. | .. |
|---|
| 56 | 60 | static struct kobject *kobj; |
|---|
| 57 | 61 | |
|---|
| 58 | 62 | static bool capture_reasons; |
|---|
| 59 | | -static bool suspend_abort; |
|---|
| 60 | | -static bool abnormal_wake; |
|---|
| 63 | +static int wakeup_reason; |
|---|
| 61 | 64 | static char non_irq_wake_reason[MAX_SUSPEND_ABORT_LEN]; |
|---|
| 62 | 65 | |
|---|
| 63 | 66 | static ktime_t last_monotime; /* monotonic time before last suspend */ |
|---|
| .. | .. |
|---|
| 149 | 152 | { |
|---|
| 150 | 153 | unsigned long flags; |
|---|
| 151 | 154 | |
|---|
| 152 | | - raw_spin_lock_irqsave(&wakeup_reason_lock, flags); |
|---|
| 155 | + spin_lock_irqsave(&wakeup_reason_lock, flags); |
|---|
| 156 | + if (wakeup_reason == RESUME_ABNORMAL || wakeup_reason == RESUME_ABORT) { |
|---|
| 157 | + spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 158 | + return; |
|---|
| 159 | + } |
|---|
| 153 | 160 | |
|---|
| 154 | 161 | if (!capture_reasons) { |
|---|
| 155 | | - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 162 | + spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 156 | 163 | return; |
|---|
| 157 | 164 | } |
|---|
| 158 | 165 | |
|---|
| 159 | 166 | if (find_node_in_list(&parent_irqs, irq) == NULL) |
|---|
| 160 | 167 | add_sibling_node_sorted(&leaf_irqs, irq); |
|---|
| 161 | 168 | |
|---|
| 162 | | - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 169 | + wakeup_reason = RESUME_IRQ; |
|---|
| 170 | + spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 163 | 171 | } |
|---|
| 164 | 172 | |
|---|
| 165 | 173 | void log_threaded_irq_wakeup_reason(int irq, int parent_irq) |
|---|
| .. | .. |
|---|
| 177 | 185 | if (!capture_reasons) |
|---|
| 178 | 186 | return; |
|---|
| 179 | 187 | |
|---|
| 180 | | - raw_spin_lock_irqsave(&wakeup_reason_lock, flags); |
|---|
| 188 | + spin_lock_irqsave(&wakeup_reason_lock, flags); |
|---|
| 189 | + |
|---|
| 190 | + if (wakeup_reason == RESUME_ABNORMAL || wakeup_reason == RESUME_ABORT) { |
|---|
| 191 | + spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 192 | + return; |
|---|
| 193 | + } |
|---|
| 181 | 194 | |
|---|
| 182 | 195 | if (!capture_reasons || (find_node_in_list(&leaf_irqs, irq) != NULL)) { |
|---|
| 183 | | - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 196 | + spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 184 | 197 | return; |
|---|
| 185 | 198 | } |
|---|
| 186 | 199 | |
|---|
| .. | .. |
|---|
| 196 | 209 | } |
|---|
| 197 | 210 | } |
|---|
| 198 | 211 | |
|---|
| 199 | | - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 212 | + spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 200 | 213 | } |
|---|
| 214 | +EXPORT_SYMBOL_GPL(log_threaded_irq_wakeup_reason); |
|---|
| 201 | 215 | |
|---|
| 202 | 216 | static void __log_abort_or_abnormal_wake(bool abort, const char *fmt, |
|---|
| 203 | 217 | va_list args) |
|---|
| 204 | 218 | { |
|---|
| 205 | 219 | unsigned long flags; |
|---|
| 206 | 220 | |
|---|
| 207 | | - raw_spin_lock_irqsave(&wakeup_reason_lock, flags); |
|---|
| 221 | + spin_lock_irqsave(&wakeup_reason_lock, flags); |
|---|
| 208 | 222 | |
|---|
| 209 | 223 | /* Suspend abort or abnormal wake reason has already been logged. */ |
|---|
| 210 | | - if (suspend_abort || abnormal_wake) { |
|---|
| 211 | | - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 224 | + if (wakeup_reason != RESUME_NONE) { |
|---|
| 225 | + spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 212 | 226 | return; |
|---|
| 213 | 227 | } |
|---|
| 214 | 228 | |
|---|
| 215 | | - suspend_abort = abort; |
|---|
| 216 | | - abnormal_wake = !abort; |
|---|
| 229 | + if (abort) |
|---|
| 230 | + wakeup_reason = RESUME_ABORT; |
|---|
| 231 | + else |
|---|
| 232 | + wakeup_reason = RESUME_ABNORMAL; |
|---|
| 233 | + |
|---|
| 217 | 234 | vsnprintf(non_irq_wake_reason, MAX_SUSPEND_ABORT_LEN, fmt, args); |
|---|
| 218 | 235 | |
|---|
| 219 | | - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 236 | + spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 220 | 237 | } |
|---|
| 221 | 238 | |
|---|
| 222 | 239 | void log_suspend_abort_reason(const char *fmt, ...) |
|---|
| .. | .. |
|---|
| 227 | 244 | __log_abort_or_abnormal_wake(true, fmt, args); |
|---|
| 228 | 245 | va_end(args); |
|---|
| 229 | 246 | } |
|---|
| 247 | +EXPORT_SYMBOL_GPL(log_suspend_abort_reason); |
|---|
| 230 | 248 | |
|---|
| 231 | 249 | void log_abnormal_wakeup_reason(const char *fmt, ...) |
|---|
| 232 | 250 | { |
|---|
| .. | .. |
|---|
| 236 | 254 | __log_abort_or_abnormal_wake(false, fmt, args); |
|---|
| 237 | 255 | va_end(args); |
|---|
| 238 | 256 | } |
|---|
| 257 | +EXPORT_SYMBOL_GPL(log_abnormal_wakeup_reason); |
|---|
| 239 | 258 | |
|---|
| 240 | 259 | void clear_wakeup_reasons(void) |
|---|
| 241 | 260 | { |
|---|
| 242 | 261 | unsigned long flags; |
|---|
| 243 | 262 | |
|---|
| 244 | | - raw_spin_lock_irqsave(&wakeup_reason_lock, flags); |
|---|
| 263 | + spin_lock_irqsave(&wakeup_reason_lock, flags); |
|---|
| 245 | 264 | |
|---|
| 246 | 265 | delete_list(&leaf_irqs); |
|---|
| 247 | 266 | delete_list(&parent_irqs); |
|---|
| 248 | | - suspend_abort = false; |
|---|
| 249 | | - abnormal_wake = false; |
|---|
| 267 | + wakeup_reason = RESUME_NONE; |
|---|
| 250 | 268 | capture_reasons = true; |
|---|
| 251 | 269 | |
|---|
| 252 | | - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 270 | + spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 253 | 271 | } |
|---|
| 254 | 272 | |
|---|
| 255 | 273 | static void print_wakeup_sources(void) |
|---|
| .. | .. |
|---|
| 257 | 275 | struct wakeup_irq_node *n; |
|---|
| 258 | 276 | unsigned long flags; |
|---|
| 259 | 277 | |
|---|
| 260 | | - raw_spin_lock_irqsave(&wakeup_reason_lock, flags); |
|---|
| 278 | + spin_lock_irqsave(&wakeup_reason_lock, flags); |
|---|
| 261 | 279 | |
|---|
| 262 | 280 | capture_reasons = false; |
|---|
| 263 | 281 | |
|---|
| 264 | | - if (suspend_abort) { |
|---|
| 282 | + if (wakeup_reason == RESUME_ABORT) { |
|---|
| 265 | 283 | pr_info("Abort: %s\n", non_irq_wake_reason); |
|---|
| 266 | | - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 284 | + spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 267 | 285 | return; |
|---|
| 268 | 286 | } |
|---|
| 269 | 287 | |
|---|
| 270 | | - if (!list_empty(&leaf_irqs)) |
|---|
| 288 | + if (wakeup_reason == RESUME_IRQ && !list_empty(&leaf_irqs)) |
|---|
| 271 | 289 | list_for_each_entry(n, &leaf_irqs, siblings) |
|---|
| 272 | 290 | pr_info("Resume caused by IRQ %d, %s\n", n->irq, |
|---|
| 273 | 291 | n->irq_name); |
|---|
| 274 | | - else if (abnormal_wake) |
|---|
| 292 | + else if (wakeup_reason == RESUME_ABNORMAL) |
|---|
| 275 | 293 | pr_info("Resume caused by %s\n", non_irq_wake_reason); |
|---|
| 276 | 294 | else |
|---|
| 277 | 295 | pr_info("Resume cause unknown\n"); |
|---|
| 278 | 296 | |
|---|
| 279 | | - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 297 | + spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 280 | 298 | } |
|---|
| 281 | 299 | |
|---|
| 282 | 300 | static ssize_t last_resume_reason_show(struct kobject *kobj, |
|---|
| .. | .. |
|---|
| 286 | 304 | struct wakeup_irq_node *n; |
|---|
| 287 | 305 | unsigned long flags; |
|---|
| 288 | 306 | |
|---|
| 289 | | - raw_spin_lock_irqsave(&wakeup_reason_lock, flags); |
|---|
| 307 | + spin_lock_irqsave(&wakeup_reason_lock, flags); |
|---|
| 290 | 308 | |
|---|
| 291 | | - if (suspend_abort) { |
|---|
| 309 | + if (wakeup_reason == RESUME_ABORT) { |
|---|
| 292 | 310 | buf_offset = scnprintf(buf, PAGE_SIZE, "Abort: %s", |
|---|
| 293 | 311 | non_irq_wake_reason); |
|---|
| 294 | | - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 312 | + spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 295 | 313 | return buf_offset; |
|---|
| 296 | 314 | } |
|---|
| 297 | 315 | |
|---|
| 298 | | - if (!list_empty(&leaf_irqs)) |
|---|
| 316 | + if (wakeup_reason == RESUME_IRQ && !list_empty(&leaf_irqs)) |
|---|
| 299 | 317 | list_for_each_entry(n, &leaf_irqs, siblings) |
|---|
| 300 | 318 | buf_offset += scnprintf(buf + buf_offset, |
|---|
| 301 | 319 | PAGE_SIZE - buf_offset, |
|---|
| 302 | 320 | "%d %s\n", n->irq, n->irq_name); |
|---|
| 303 | | - else if (abnormal_wake) |
|---|
| 321 | + else if (wakeup_reason == RESUME_ABNORMAL) |
|---|
| 304 | 322 | buf_offset = scnprintf(buf, PAGE_SIZE, "-1 %s", |
|---|
| 305 | 323 | non_irq_wake_reason); |
|---|
| 306 | 324 | |
|---|
| 307 | | - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 325 | + spin_unlock_irqrestore(&wakeup_reason_lock, flags); |
|---|
| 308 | 326 | |
|---|
| 309 | 327 | return buf_offset; |
|---|
| 310 | 328 | } |
|---|
| .. | .. |
|---|
| 340 | 358 | sleep_time.tv_nsec); |
|---|
| 341 | 359 | } |
|---|
| 342 | 360 | |
|---|
| 343 | | -#if defined(CONFIG_ROCKCHIP_SIP) |
|---|
| 344 | | -static ssize_t total_suspend_wfi_time_show(struct kobject *kobj, |
|---|
| 345 | | - struct kobj_attribute *attr, |
|---|
| 346 | | - char *buf) |
|---|
| 347 | | -{ |
|---|
| 348 | | - struct arm_smccc_res res; |
|---|
| 349 | | - unsigned long wfi_time_ms; |
|---|
| 350 | | - |
|---|
| 351 | | - res = sip_smc_get_suspend_info(SUSPEND_WFI_TIME_MS); |
|---|
| 352 | | - if (res.a0) |
|---|
| 353 | | - wfi_time_ms = 0; |
|---|
| 354 | | - else |
|---|
| 355 | | - wfi_time_ms = res.a1; |
|---|
| 356 | | - |
|---|
| 357 | | - return sprintf(buf, "%lu.%02lu\n", wfi_time_ms / MSEC_PER_SEC, |
|---|
| 358 | | - (wfi_time_ms % MSEC_PER_SEC) / 10); |
|---|
| 359 | | -} |
|---|
| 360 | | -#endif |
|---|
| 361 | | - |
|---|
| 362 | 361 | static struct kobj_attribute resume_reason = __ATTR_RO(last_resume_reason); |
|---|
| 363 | 362 | static struct kobj_attribute suspend_time = __ATTR_RO(last_suspend_time); |
|---|
| 364 | | -#if defined(CONFIG_ROCKCHIP_SIP) |
|---|
| 365 | | -static struct kobj_attribute suspend_wfi_time = __ATTR_RO(total_suspend_wfi_time); |
|---|
| 366 | | -#endif |
|---|
| 367 | 363 | |
|---|
| 368 | 364 | static struct attribute *attrs[] = { |
|---|
| 369 | 365 | &resume_reason.attr, |
|---|
| 370 | 366 | &suspend_time.attr, |
|---|
| 371 | | -#if defined(CONFIG_ROCKCHIP_SIP) |
|---|
| 372 | | - &suspend_wfi_time.attr, |
|---|
| 373 | | -#endif |
|---|
| 374 | 367 | NULL, |
|---|
| 375 | 368 | }; |
|---|
| 376 | 369 | static struct attribute_group attr_group = { |
|---|